-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
260 lines (216 loc) · 8.77 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
plugins {
id 'java-library'
id 'maven-publish'
id 'jacoco-report-aggregation'
id 'io.freefair.lombok' version libs.versions.delombok
}
final def TEST_MODULE = 'testing'
final def DEMO_MODULE = 'demo'
final def VERSION_VARIABLE = 'MINECRAFT_VERSION'
group = 'it.fulminazzo'
version = '4.1'
allprojects {
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'jacoco-report-aggregation'
apply plugin: 'io.freefair.lombok'
group = "${rootProject.group}"
version = "${rootProject.version}"
description = 'Yet Another GUI Library to create and manage custom items and user interfaces in Minecraft.'
def latestVersion
def legacyVersion
def obsoleteVersion
this.ext.setupMinecraftVersion = {
final def minecraftVersion = System.getenv(VERSION_VARIABLE)
latestVersion = minecraftVersion == null ? libs.versions.spigot.latest.get() : minecraftVersion
legacyVersion = minecraftVersion == null ? libs.versions.spigot.legacy.get() : minecraftVersion
obsoleteVersion = minecraftVersion == null ? libs.versions.spigot.obsolete.get() : minecraftVersion
}
this.ext.getParentFromProject = { project ->
return new HashMap<>(project.getProperties()).get('parent')
}
this.ext.getProjectGroupId = {
String groupId = ""
Project tmp = parent
while (tmp != null) {
groupId = "${tmp.name}.${groupId}"
tmp = getParentFromProject(tmp)
}
if (groupId.size() > 0)
groupId = ".${groupId.substring(0, groupId.length() - 1)}"
return "${rootProject.group}${groupId}"
}
this.ext.getJBukkitModule = { minecraftVersion ->
String numVersion = minecraftVersion.substring(2, minecraftVersion.indexOf('.', 2))
def index = numVersion.indexOf('-')
if (index != -1) numVersion = numVersion.substring(0, index)
return "${libs.versions.jbukkitartifact.get()}:${numVersion}:${libs.versions.jbukkit.get()}"
}
this.ext.getAppropriateJavaVersion = {
String numVersion = latestVersion.substring(2, latestVersion.indexOf('.', 2))
def index = numVersion.indexOf('-')
if (index != -1) numVersion = numVersion.substring(0, index)
return numVersion as Integer >= 20 ? 17 : 8
}
setupMinecraftVersion()
repositories {
mavenCentral()
maven {
name = 'spigotmc-repo'
url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
}
maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url = 'https://oss.sonatype.org/content/repositories/central' }
maven {
name = 'JitPack'
url = 'https://jitpack.io'
}
maven {
name = 'Fulminazzo repository'
url = 'https://repo.fulminazzo.it/releases'
}
}
dependencies {
// Common dependencies
compileOnly libs.lombok
annotationProcessor libs.lombok
compileOnly libs.annotations
testCompileOnly libs.annotations
implementation libs.fulmicollection
testCompileOnly libs.lombok
testAnnotationProcessor libs.lombok
def projectName = project.name
// Common submodules dependencies
if (projectName.contains('-')) {
def name = projectName.substring(0, projectName.indexOf('-'))
def id = projectName.substring(projectName.indexOf('-') + 1)
// Import base if submodule is NOT base
if (!projectName.contains('base')) api(project(":${name}:${name}-base"))
// Import common corresponding submodule
if (name != 'common' && id != 'legacy' && id != 'obsolete')
api(project(":common:common-${id}"))
}
// Common modules dependencies
if (['common', 'wrappers', 'item', 'gui'].contains(projectName)) {
for (def s : ['base', 'serializer', 'bukkit'])
api(project(":${projectName}:${projectName}-${s}"))
}
// Serializer dependencies
if (projectName.contains('serializer')) api(libs.yamlparser)
// Bukkit dependencies
if (projectName.contains('bukkit') || projectName.contains('demo')) {
compileOnly libs.spigot
testCompileOnly libs.spigot.latest
testRuntimeOnly "org.spigotmc:spigot-api:${latestVersion}"
// JBukkit library
testImplementation getJBukkitModule(latestVersion)
}
// Legacy dependencies
if (projectName.contains('legacy')) {
testCompileOnly libs.spigot.legacy
testRuntimeOnly "org.spigotmc:spigot-api:${legacyVersion}"
testImplementation getJBukkitModule(legacyVersion)
}
// Obsolete dependencies
if (projectName.contains('obsolete')) {
testCompileOnly libs.spigot.obsolete
testRuntimeOnly "org.spigotmc:spigot-api:${obsoleteVersion}"
testImplementation getJBukkitModule(obsoleteVersion)
}
if (!projectName.contains(TEST_MODULE)) {
def modulesMap = [
'base':'base', 'serializer':'serializer', 'bukkit':'bukkit',
'obsolete':'bukkit', 'legacy':'bukkit'
]
// If not test module, import corresponding test module
for (m in modulesMap.keySet())
if (projectName.contains(m))
testImplementation project(":${TEST_MODULE}:${TEST_MODULE}-${modulesMap[m]}")
} else if (projectName.contains('bukkit')) {
// If test module (bukkit version), implement base JBukkit
implementation "${libs.versions.jbukkitartifact.get()}:base:${libs.versions.jbukkit.get()}"
}
// Demo module
if (projectName == DEMO_MODULE) {
rootProject.subprojects
.findAll { it.name != TEST_MODULE && it.name != DEMO_MODULE }
.each { implementation project(it.path) }
testImplementation getJBukkitModule(latestVersion)
}
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(getAppropriateJavaVersion())
}
}
if (project.name == TEST_MODULE) return
test {
def projectName = project.name
if (System.getenv(VERSION_VARIABLE) == null) {
if (projectName.contains('bukkit')) environment VERSION_VARIABLE, latestVersion
else if (projectName.contains('legacy')) environment VERSION_VARIABLE, legacyVersion
else if (projectName.contains('obsolete')) environment VERSION_VARIABLE, obsoleteVersion
}
def env = System.getenv(VERSION_VARIABLE)
if (env != null) println "Testing ${projectName} with Minecraft ${env}"
useJUnitPlatform()
}
tasks.register('testBukkit') {
if (System.getenv(VERSION_VARIABLE) == null)
throw new IllegalArgumentException("Please specify environment variable '${VERSION_VARIABLE}' before proceeding")
println "Running tests with Minecraft version ${latestVersion} and Java version ${getAppropriateJavaVersion()}"
subprojects.findAll { it.path.contains('bukkit') }.each {
dependsOn "${it.path}:clean"
dependsOn "${it.path}:test"
}
}
tasks.register('sourcesJar', Jar) {
from sourceSets.main.delombokTask
archiveClassifier = 'sources'
}
tasks.register('javadocJar', Jar) {
from javadoc
archiveClassifier = 'javadoc'
}
publishing {
publications {
maven(MavenPublication) {
groupId = getProjectGroupId().toString().toLowerCase()
artifactId = "${project.name.toLowerCase()}"
version = "${rootProject.version}"
from components.java
artifact sourcesJar
artifact javadocJar
}
}
repositories {
maven {
url 'https://repo.fulminazzo.it/releases'
credentials {
username = System.getenv('REPO_USERNAME')
password = System.getenv('REPO_PASSWORD')
}
authentication {
basic(BasicAuthentication)
}
}
}
}
}
dependencies {
subprojects.findAll { it.name != TEST_MODULE && it.name != DEMO_MODULE } .each { api project(it.path) }
implementation project(":${DEMO_MODULE}")
}
tasks.register("aggregateJavaDoc") {
allprojects.forEach { dependsOn "${it.path}:javadoc" }
doLast {
JavaDocUtils.aggregateJavaDoc("html/docs", rootProject.name, rootProject.version, TEST_MODULE)
}
}
testCodeCoverageReport {
dependsOn test
reports {
xml.required = true
csv.required = true
}
}