-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
242 lines (195 loc) · 7.09 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
import java.text.SimpleDateFormat
plugins {
// Java plugin for Java projects.
id 'java'
// Checkstyle plugin for code style checking.
id 'checkstyle'
// SpotBugs plugin for static analysis.
id 'com.github.spotbugs' version '6.0.26'
// Shadow plugin for creating fat JARs.
id 'io.github.goooler.shadow' version '8.1.8'
}
// Group ID for the project.
group = 'com.altiran.dropstop'
// Get the current time in UTC in the format 'yyMMdd-HHmm'.
static def getTime() {
SimpleDateFormat sdf = new SimpleDateFormat('yyMMdd-HHmm')
sdf.setTimeZone(TimeZone.getTimeZone('UTC'))
return sdf.format(new Date()).toString()
}
// Set version to version property if supplied via 'gradle.properties' file or generate a timestamped version.
String shortVersion = null
if (hasProperty('projectVersion')) {
if (projectVersion.charAt(0) == (char) 'v') {
shortVersion = projectVersion.substring(1).toUpperCase()
} else {
shortVersion = projectVersion.toUpperCase()
}
}
// If the tag includes '-RC-' or no tag is supplied, append '-SNAPSHOT' to the version.
int rcIdx
if (shortVersion == null || shortVersion == '') {
version = getTime() + '-SNAPSHOT'
} else if ((rcIdx = shortVersion.indexOf('-RC-')) != -1) {
version = shortVersion.substring(0, rcIdx) + '-SNAPSHOT'
} else {
version = shortVersion
}
// Get the compatible Java version from 'gradle.properties' file.
def targetJavaVersion = Integer.valueOf(javaVersion)
// Set the Java version for the project.
java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
}
// Define the repositories to use for dependencies.
repositories {
// PaperMC Maven repository.
maven {
name 'papermc'
url 'https://repo.papermc.io/repository/maven-public/'
content {
includeModule('io.papermc.paper', 'paper-api')
includeModule('io.papermc', 'paperlib')
includeModule('net.md-5', 'bungeecord-chat')
}
}
// Minecraft Maven repository.
maven {
name 'minecraft'
url 'https://libraries.minecraft.net'
content {
includeModule('com.mojang', 'brigadier')
}
}
// SpigotMC Maven repository.
maven {
name 'spigotmc'
url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots'
}
// Sonatype Maven repository.
maven {
name 'sonatype'
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
// JitPack Maven repository.
maven {
name 'jitpack'
url 'https://jitpack.io'
}
// Concurrentia Maven repository.
maven {
name 'concurrentia'
url 'https://raw.githubusercontent.com/Altiran/concurrentia/main/repo'
}
// JCenter Maven repository.
mavenCentral()
}
// Define the project dependencies.
dependencies {
/*******************************************
* MINECRAFT VERSION-SPECIFIC DEPENDENCIES *
*******************************************/
// Paper API for compilation only. The server will provide the implementation at runtime.
compileOnly 'io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT'
// MockBukkit
testImplementation 'com.github.seeseemelk:MockBukkit-v1.20:3.93.2'
/********************************
* PLUGIN-SPECIFIC DEPENDENCIES *
********************************/
// Only for suggesting PaperMC in server log messages (optional).
implementation 'io.papermc:paperlib:1.0.8'
// Jakarta Annotation API
compileOnly 'jakarta.annotation:jakarta.annotation-api:3.0.0'
// SpotBugs for static analysis (only at compile time and testing).
compileOnly 'com.github.spotbugs:spotbugs-annotations:4.8.6'
testCompileOnly 'com.github.spotbugs:spotbugs-annotations:4.8.6'
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.13.0'
// Concurrentia for asynchronous tests.
testImplementation 'com.altiran:concurrentia:1.0.3'
// SLF4J for testing only. The server will provide the implementation at runtime.
testImplementation 'org.slf4j:slf4j-simple:2.0.16'
// JUnit Jupiter API provides the classes and methods necessary to write tests.
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.3'
// JUnit Platform to discover, filter, and execute tests.
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
// Configure the test task.
test {
// Use JUnit Platform for running tests.
useJUnitPlatform()
// Always run tests. Never skip them even if they are up-to-date.
outputs.upToDateWhen { false }
}
// Configure processing of resources when building the project.
processResources {
// Only include resources with UTF-8 encoding.
filteringCharset 'UTF-8'
// Inject the project name, version, and package into the plugin.yml file.
filesMatching('**/plugin.yml') {
expand(NAME: rootProject.name, VERSION: version, PACKAGE: project.group.toString())
}
}
// Configure the Checkstyle plugin.
checkstyle {
// Checkstyle version to use.
toolVersion '10.20.1'
// No limit on the number of warnings.
maxWarnings = 0
}
// Configure the Checkstyle task.
configurations.checkstyle {
// Use Google Guava instead of Google Collections.
resolutionStrategy.capabilitiesResolution.withCapability('com.google.collections:google-collections') {
select('com.google.guava:guava:33.3.1-jre')
}
}
// Configure the SpotBugs plugin.
spotbugs {
// Specify the SpotBugs exclusion filter file.
excludeFilter = file('./config/spotbugs/spotbugs.xml')
}
// Configure Shadow plugin.
shadowJar {
// Don't append anything to the final JAR name.
archiveClassifier.set('' as String)
// Relocate PaperLib classes to avoid conflicts.
relocate 'io.papermc.lib', 'shadow.io.papermc.paperlib'
// Remove unused classes from the final JAR.
minimize()
}
// Disable JAR task.
jar.enabled = false
// Replace with shadowJar task instead.
assemble.dependsOn(shadowJar)
// Define custom print project name task.
tasks.register('printProjectName') {
// Print the project name when the task is executed.
doLast {
println rootProject.name
}
}
// Define custom release task.
tasks.register('release') {
// Build the project before releasing.
dependsOn build
doLast {
if (!version.endsWith('-SNAPSHOT')) {
// Rename final JAR to trim off version information
shadowJar.archiveFile.get().getAsFile().renameTo(layout.buildDirectory.get().toString() + File.separator + 'libs' + File.separator + rootProject.name + '.jar')
}
}
}
// Configure the JavaCompile task.
tasks.withType(JavaCompile).configureEach {
// Set the encoding to UTF-8.
options.encoding = 'UTF-8'
// Set the Java version to the target Java version if it is Java 10 or higher.
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
options.release.set(targetJavaVersion)
}
}