-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpublishScript.gradle
More file actions
83 lines (71 loc) · 2.97 KB
/
publishScript.gradle
File metadata and controls
83 lines (71 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//This script is internal so that the example mod can be published to the maven repository,
//You can delete this script, just make sure to delete the corresponding `apply` line in build.gradle
ext.mavenLocalUrl = repositories.mavenLocal().url.toString()
def archiveName = project.base.archivesName.get()
tasks.register('checkArtifactExists') {
doLast {
// Skip this task if --force is present
if (project.hasProperty('force')) {
logger.lifecycle("Skipping artifact existence check due to --force flag.")
return
}
def repoUrl = project.hasProperty('mavenRepoUrl') ? project.mavenRepoUrl : mavenLocalUrl
def projectGroup = "${project.group}.${archiveName}"
def gradleGroup = "${projectGroup}.gradle.plugin"
def artifactPath = "${repoUrl}/${projectGroup.replace('.', '/')}/${gradleGroup}/${project.version}/${gradleGroup}-${project.version}.jar"
logger.lifecycle("Checking if artifact exists at: $artifactPath")
if (artifactPath.startsWith('file:/')) {
def file = new File(new URI(artifactPath))
if (file.exists()) {
throw new IllegalStateException("Artifact '${artifactPath}' already exists. Publishing aborted.")
}
} else {
def url = new URL(artifactPath)
def connection = url.openConnection()
connection.setRequestMethod('HEAD')
if (connection.responseCode == 200) {
throw new IllegalStateException("Artifact '${artifactPath}' already exists. Publishing aborted.")
}
}
logger.lifecycle("Artifact does not exist, proceeding with publish.")
}
}
tasks.named('publish') {
dependsOn 'checkArtifactExists'
}
tasks.withType(PublishToMavenRepository).configureEach {
if (it.name.equals("publishPluginMavenPublicationToMavenRepository")) {
logger.lifecycle("Disabling task: ${it.name}")
it.enabled = false
}
}
tasks.register('capabilitiesJar', Jar) {
archiveFileName = "workspace-capabilities-${project.version}.jar"
from(sourceSets.main.output) {
include 'capabilities.json'
include 'com/wildermods/workspace/capabilities/**'
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
groupId = project.group + ".workspace"
artifactId = 'com.wildermods.workspace.gradle.plugin' // Set the expected plugin artifact ID
version = project.version
// Attach sources JAR to the publication
artifact sourceJar
}
capabilities(MavenPublication) {
groupId = project.group
artifactId = "workspace-capabilities"
version = project.version
artifact tasks.named('capabilitiesJar')
}
}
repositories {
maven {
url = uri(project.hasProperty('mavenRepoUrl') ? project.mavenRepoUrl : mavenLocalUrl) // Default to mavenLocal if no custom URL is provided
}
}
}