-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
181 lines (152 loc) · 6.11 KB
/
build.gradle
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
plugins {
id 'java-gradle-plugin'
id 'eclipse'
id 'maven-publish'
}
repositories {
mavenCentral()
maven {
url "https://maven.fabricmc.net/"
}
maven {
url "https://maven.wildermods.com/"
}
}
version = workspaceVersion
group = "com.wildermods"
archivesBaseName = "workspace"
sourceCompatibility = '17'
targetCompatibility = '17'
//dependencies are defined in [project root]/gradle/deps.versions.toml
dependencies {
gradleApi()
implementation libs.commons.lang
implementation libs.commons.text
implementation libs.commons.io
implementation libs.fabric.loom
implementation libs.vineflower
implementation libs.gson
}
import org.apache.tools.ant.filters.ReplaceTokens
task processSource(type: Sync) {
from sourceSets.main.java.srcDirs
into "$buildDir/processedSrc"
// DEBUG CODE TO VIEW AVAILABLE METHODS - DO NOT REMOVE
/*
logger.lifecycle("Available versions:")
libs.versions.properties.each { key, value ->
logger.lifecycle("$key -> $value")
value.properties.each { key2, value2 ->
logger.lifecycle("$key -> $value -> [$key2 -> $value2]")
// Check if value2 is not null before accessing its methods and properties
if (value2 != null) {
// Print the full method signatures for value2
logger.lifecycle("Methods for $value2:")
value2.metaClass.methods.each { method ->
// Get the method name and parameter types
def methodSignature = "${method.name}(${method.parameterTypes*.name.join(', ')}) -> ${method.returnType.name}"
logger.lifecycle("Method Signature: $methodSignature")
}
// Optionally, print properties as well (if needed)
value2.metaClass.properties.each { property ->
logger.lifecycle("Property: ${property.name}")
}
} else {
logger.lifecycle("value2 is null for $key2")
}
}
}
*/
//The version of the WilderWorkspace gradle plugin
inputs.property 'workspaceVersion', workspaceVersion
def providerVersion = libs.versions.provider.version.get()
def fabricLoaderVersion = libs.versions.fabric.loader.version.get()
//dependencies for building and running WilderWorkspace gradle plugin itself
def commonsIOVersion = libs.versions.commons.io.version.get()
def commonsLangVersion = libs.versions.commons.Lang.version.get()
def commonsTextVersion = libs.versions.commons.Text.version.get()
def vineFlowerVersion = libs.versions.vineflower.version.get()
def loomVersion = libs.versions.fabric.Loom.version.get()
def gsonVersion = libs.versions.gson.version.get()
//transitive dependencies
def log4jVersion = libs.versions.log4j.version.get()
filter(ReplaceTokens, tokens: [
//The version of the WilderWorkspace gradle plugin
workspaceVersion: workspaceVersion,
//dependencies that projects using WilderWorkspace will need in order to mod Wildermyth
providerVersion: providerVersion,
fabricLoaderVersion: fabricLoaderVersion,
gsonVersion: gsonVersion,
//dependencies for building and running WilderWorkspace gradle plugin itself
commonsIOVersion: commonsIOVersion,
commonsLangVersion: commonsLangVersion,
commonsTextVersion: commonsTextVersion,
vineFlowerVersion: vineFlowerVersion,
loomVersion: loomVersion,
//transitive dependencies
log4jVersion: log4jVersion
])
}
compileJava {
source = fileTree(dir: "$buildDir/processedSrc", include: '**/*.java')
dependsOn processSource
}
ext.mavenLocalUrl = repositories.mavenLocal().url.toString()
task sourceJar(type: Jar) {
from sourceSets.main.allSource
archiveClassifier.set('sources')
}
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}.${project.archivesBaseName}"
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
}
}
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
}
}
repositories {
maven {
url = uri(project.hasProperty('mavenRepoUrl') ? project.mavenRepoUrl : mavenLocalUrl) // Default to mavenLocal if no custom URL is provided
}
}
}