-
Notifications
You must be signed in to change notification settings - Fork 19
/
build.gradle
315 lines (271 loc) · 10 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
import io.franzbecker.gradle.lombok.task.DelombokTask
plugins {
id 'com.gradleup.shadow' version '8.3.0'
id 'io.franzbecker.gradle-lombok' version '5.0.0'
}
repositories {
mavenCentral()
}
allprojects {
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'com.gradleup.shadow'
// no lombok for that project, cause its doing naughty things with stubing java.lang classes
if (project != project(':headlessmc-modlauncher')) {
// Consider switching to https://github.com/freefair/gradle-plugins/tree/main/lombok-plugin looks more maintained?
apply plugin: 'io.franzbecker.gradle-lombok'
lombok {
version '1.18.34'
}
}
group 'me.earth.headlessmc'
version rootProject.project_version
repositories {
mavenCentral()
maven {
name '3arthMaven'
url 'https://3arthqu4ke.github.io/maven'
}
maven {
name 'JitPackMaven'
url 'https://jitpack.io'
}
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
compileJava {
if (JavaVersion.current().isJava9Compatible()) {
options.compilerArgs.addAll(['--release', '8'])
}
}
configurations {
jarLibs
implementation.extendsFrom jarLibs
jarLibsApi
api.extendsFrom jarLibsApi
}
dependencies {
compileOnly 'org.jetbrains:annotations:24.1.0'
testCompileOnly 'org.jetbrains:annotations:24.1.0'
// no lombok for modlauncher cause we do bad hacks there in the java9 stub.
if (project != project(':headlessmc-modlauncher')) {
compileOnly 'org.projectlombok:lombok:1.18.34'
annotationProcessor 'org.projectlombok:lombok:1.18.34'
testCompileOnly 'org.projectlombok:lombok:1.18.34'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.34'
}
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.0'
}
test {
useJUnitPlatform()
testLogging {
events "failed"
exceptionFormat "full"
}
finalizedBy jacocoTestReport
}
jacocoTestReport {
dependsOn test
}
jar {
archivesBaseName = project.name
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
java {
withSourcesJar()
withJavadocJar()
}
// TODO: even though we are doing all of this Intellij
// still complains about bytecode not matching the source...
if (sourceSets.main.java.srcDirs.stream().anyMatch { it.exists()}
&& project != project(':headlessmc-modlauncher')) {
tasks.register('delombok', DelombokTask) {
dependsOn compileJava
ext.outputDir = file(layout.buildDirectory.dir('delombok'))
outputs.dir(ext.outputDir)
sourceSets.main.java.srcDirs.each {
if (it.exists()) {
inputs.dir(it)
args(it, '-f', 'suppressWarnings:skip',
'-f', 'generated:skip',
'-f', 'danceAroundIdeChecks:skip',
'-f', 'generateDelombokComment:skip',
'-f', 'javaLangAsFQN:skip',
'-d', ext.outputDir)
}
}
}
javadoc {
dependsOn delombok
source = delombok.outputDir
}
sourcesJar {
dependsOn delombok
from delombok.outputDir
// I tried every single exclude/include pattern but I could not get any to work
exclude (fileTreeElement -> {
return !((FileTreeElement) fileTreeElement)
.getFile()
.toPath()
.toAbsolutePath()
.startsWith(delombok.outputDir.toPath().toAbsolutePath())
})
}
javadoc {
options.addStringOption('Xdoclint:none', '-quiet')
options.linkSource true
}
}
jar {
archiveClassifier.set('dev')
}
shadowJar {
configurations = [project.configurations.jarLibs, project.configurations.jarLibsApi]
archiveClassifier.set('')
}
jar.finalizedBy(shadowJar)
def pubSuffix = System.getenv('IS_MAVEN_PUB') != null
? ''
: System.getenv('GITHUB_RUN_NUMBER') != null && System.getenv('GITHUB_SHA') != null
? "-${System.getenv('GITHUB_RUN_NUMBER')}-${System.getenv('GITHUB_SHA').substring(0, 7)}"
: project.version.endsWith('-SNAPSHOT')
? ''
: ''
publishing {
publications {
"${project.name.toLowerCase(Locale.ENGLISH)}"(MavenPublication) {
((MavenPublication) it).groupId "${project.group}"
((MavenPublication) it).artifactId "${project.archivesBaseName.toLowerCase(Locale.ENGLISH)}"
((MavenPublication) it).version "${project.version}${pubSuffix}"
// TODO: testFixtures are part of commons artifact?
// Exclude shadowJars from publication
components.withType(AdhocComponentWithVariants).forEach { c ->
c.withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
skip()
}
}
from components.java
}
}
repositories {
// mavenLocal()
if (System.getenv('DEPLOY_TO_GITHUB_PACKAGES_URL') != null) {
maven {
name = 'GithubPagesMaven'
url = System.getenv('DEPLOY_TO_GITHUB_PACKAGES_URL')
credentials {
username = System.getenv('GITHUB_USER')
password = System.getenv('GITHUB_TOKEN')
}
}
} else {
maven {
name = 'BuildDirMaven'
url = rootProject.layout.buildDirectory.dir('maven')
}
}
}
}
publish {
dependsOn(build)
}
tasks.withType(Test).tap {
configureEach {
jacoco {
// our classloader potentially includes no ProtectionDomains?
includeNoLocationClasses true
jacoco.excludes = ['jdk.internal.*', 'me.earth.headlessmc.lwjgl.agent.*']
}
}
}
}
javadoc {
source subprojects.collect { it.sourceSets.main.allJava }
classpath = files(subprojects.collect { it.sourceSets.main.compileClasspath })
}
dependencies {
// create maven publication that contains all modules
api project(':headlessmc-api')
api project(':headlessmc-auth')
api project(':headlessmc-jline')
api project(':headlessmc-logging')
api project(':headlessmc-launcher')
api project(':headlessmc-launcher-wrapper')
api project(':headlessmc-modlauncher')
api project(':headlessmc-lwjgl')
api project(':headlessmc-runtime')
}
tasks.register('jacocoRootReport', JacocoReport) {
description = 'Generates an aggregate report from all subprojects'
group = 'verification'
dependsOn(subprojects.test)
additionalSourceDirs.from = files(subprojects.sourceSets.main.allSource.srcDirs)
sourceDirectories.from = files(subprojects.sourceSets.main.allSource.srcDirs)
classDirectories.from = files(subprojects.sourceSets.main.output)
executionData.from = files(subprojects.jacocoTestReport.executionData)
reports {
xml.required.set(true)
}
}
tasks.register('copyJars', Copy) {
dependsOn subprojects.shadowJar
subprojects.each { subproject ->
// jfx jar is > 100MB, I do not want to fill my github storage?
if (subproject.name != 'headlessmc-launcher-jfx') {
from(subproject.shadowJar)
}
}
into project.file(System.getProperty('hmc.jar.dir', 'build/libs'))
}
build {
dependsOn(subprojects.shadowJar)
finalizedBy(copyJars)
}
// the launchers report will otherwise contain coverage data about some of the
// libraries we use in those two jars, e.g. xdarks Deencapsulation
//noinspection ConfigurationAvoidance (idk does not seem to work with it)
tasks.withType(JacocoReport) {
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
def tree = fileTree(dir: it, exclude: [
'**/headlessmc/headlessmc-launcher.jar',
'**/headlessmc/headlessmc-runtime.jar',
'**/headlessmc/headlessmc-lwjgl.jar',
'**/headlessmc/forge-cli.jar',
'me/earth/headlessmc/lwjgl/agent/**',
'me/earth/headlessmc/web/**',
'me/earth/headlessmc/web/**/*.*',
'me/earth/headlessmc/web/cheerpj/**/*.*',
'me/earth/headlessmc/web/cheerpj/plugin/**',
'me/earth/headlessmc/web/cheerpj/plugin/*.*'
])
// because 'me/earth/headlessmc/web/cheerpj/plugin/**' does not work
return tree.exclude { details ->
return details.file.canonicalPath.contains('headlessmc-web')
}
}))
}
reports {
xml.required.set(true)
}
}
allprojects {
afterEvaluate {
tasks.withType(GenerateMavenPom).configureEach {
if (it.pom == null) {
return
}
it.pom.withXml {
asNode().dependencies.dependency.each { dependency ->
if (dependency.artifactId.last().value().last() in ['junit-jupiter-api', 'junit-jupiter-engine', 'forgecli']) {
assert dependency.parent().remove(dependency)
}
}
}
}
}
}
generateMetadataFileForHeadlessmcPublication.mustRunAfter(copyJars)