-
Notifications
You must be signed in to change notification settings - Fork 16
/
build.gradle
272 lines (233 loc) · 8.52 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
import io.franzbecker.gradle.lombok.task.DelombokTask
plugins {
id 'com.github.johnrengelman.shadow' version '7.1.2'
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.github.johnrengelman.shadow'
apply plugin: 'io.franzbecker.gradle-lombok'
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
jarLibsApi
}
dependencies {
compileOnly 'org.jetbrains:annotations:24.1.0'
compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
testCompileOnly 'org.projectlombok:lombok:1.18.30'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.30'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1'
implementation configurations.jarLibs
api configurations.jarLibsApi
}
test {
useJUnitPlatform()
testLogging {
events "failed"
exceptionFormat "full"
}
finalizedBy jacocoTestReport
}
jacocoTestReport {
dependsOn test
}
jar {
archivesBaseName = project.name
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
java {
// because we are using lomboks var
if (!JavaVersion.current().isJava9Compatible()) {
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()}
// var keyword causes issues in DelombokTask with newer jdks
&& !JavaVersion.current().isJava9Compatible()) {
tasks.register('delombok', DelombokTask) {
dependsOn compileJava
ext.outputDir = file(buildDir.toPath().resolve('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
options.addStringOption('Xdoclint:none', '-quiet')
options.linkSource true
}
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())
})
}
}
jar {
classifier 'dev'
}
shadowJar {
configurations = [project.configurations.jarLibs, project.configurations.jarLibsApi]
classifier ''
}
jar.finalizedBy(shadowJar)
// since we are not creating javadoc and sources on java 9+ skip
if (!JavaVersion.current().isJava9Compatible()) {
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)}"
: '-local'
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)
}
} else {
project.logger.warn('Cannot publish on Java 9+ as we are not generating JavaDocs!')
}
}
dependencies {
// create maven publication that contains all modules
api project(':headlessmc-api')
api project(':headlessmc-commons')
api project(':headlessmc-launcher')
api project(':headlessmc-lwjgl')
api project(':headlessmc-runtime')
}
tasks.register('jacocoRootReport', JacocoReport) {
description = 'Generates an aggregate report from all subprojects'
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 {
html.enabled true
xml.enabled 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 {
fileTree(dir: it, exclude: [
'**/headlessmc/headlessmc-runtime.jar',
'**/headlessmc/headlessmc-lwjgl.jar',
'**/headlessmc/forge-cli.jar',
])
}))
}
}
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)
}
}
}
}
}
}