forked from Shopkeepers/Shopkeepers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
262 lines (232 loc) · 8.75 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
plugins {
id 'base' // Adds the clean task to the root project
id 'com.github.johnrengelman.shadow' version '7.1.2' apply false
id 'org.checkerframework' version '0.6.39' apply false
// Useful for build debugging:
// https://gitlab.com/barfuin/gradle-taskinfo
//id 'org.barfuin.gradle.taskinfo' version '1.3.0'
id 'org.sonarqube' version '5.0.0.4638'
}
sonar {
properties {
property 'sonar.projectKey', 'Shopkeepers_Shopkeepers'
property 'sonar.organization', 'shopkeepers'
property 'sonar.host.url', 'https://sonarcloud.io'
}
}
ext.getGitHash = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
// We embed the git hash into jar files, and also use it for the plugin version of snapshot builds.
ext.buildVersion = version + '+' + getGitHash()
ext.isSnapshot = version.contains('-SNAPSHOT')
ext.pluginVersion = isSnapshot ? buildVersion : version
println 'User home: ' + System.properties['user.home']
println 'Local Maven repository: ' + repositories.mavenLocal().url.path
println 'Project version: ' + version
println 'Build version: ' + buildVersion
println 'Plugin version: ' + pluginVersion
ext.configureJarTask = { project, jarTask ->
jarTask.inputs.property 'group', project.group
jarTask.inputs.property 'artifactId', project.artifactId
jarTask.inputs.property 'buildVersion', project.buildVersion
jarTask.archiveBaseName = project.artifactId
jarTask.manifest {
attributes 'Implementation-Title': "${project.group}:${project.artifactId}",
'Implementation-Version': project.buildVersion
}
}
ext.configureJarTaskWithMavenMetadata = { project, jarTask ->
configureJarTask(project, jarTask)
// If the maven-publish plugin is used, include the generated Maven metadata files into the jar:
project.plugins.withId('maven-publish') {
jarTask.into("META-INF/maven/$project.group/$project.artifactId") {
from { project.generatePomFileForMavenJavaPublication } {
rename '.*', 'pom.xml'
}
from { project.generateMavenPomPropertiesFile }
}
}
}
ext.configureShadowArtifacts = { project ->
project.artifacts {
// Similar to the regular jar, declare the shadow jar as output of the project for any
// projects that depend on it.
archives project.shadowJar
apiElements project.shadowJar
runtimeElements project.shadowJar
}
}
ext.configureMavenPublication = { project, publication ->
publication.artifactId = project.artifactId
publication.pom {
name = project.name
description = project.description
url = dboUrl
scm {
url = scmUrl
connection = scmConnection
developerConnection = scmDeveloperConnection
}
// Note: Gradle intentionally ignores and omits repositories from the pom file.
// https://github.com/gradle/gradle/issues/15932
// https://github.com/gradle/gradle/issues/8811
// Note: Gradle maps all api dependencies to 'compile' scope and all implementation
// dependencies to 'runtime' scope (instead of 'provided' scope). Although this does not
// match the project's compile configuration (since the runtime scope is not considered part
// of the project's compilation classpath), this is not an issue because the primary purpose
// of the published pom file is not to configure the build of this project, but only to
// ensure that any transitive compile and runtime dependencies are declared for consuming
// projects.
}
}
ext.configureShadowMavenPublication = { project, publication ->
configureMavenPublication(project, publication)
// Adding the java component here, instead of the shadow component, ensures that we generate the
// default pom contents, including entries for all dependencies. The shadow component would omit
// all dependencies (except those of the 'shadow' configuration), even if we configure the
// shadowJar task to only include some of the dependencies.
// However, the published artifacts are overridden to only publish the shadow jar instead.
publication.from project.components.java
publication.artifact project.shadowJar
}
ext.disableMavenPublications = { project ->
project.tasks.withType(AbstractPublishToMaven).configureEach {
enabled = false
}
}
allprojects {
// Set up default properties if they match the root project's values:
// Note: In order to allow subprojects to define their values of these properties inside their
// build files (instead of their 'gradle.properties' files), any task configurations that depend
// on these properties have to be deferred until after the subproject's build script has been
// evaluated.
if (project.properties['artifactId'] == rootProject.properties['artifactId']) {
project.ext.artifactId = project.name
}
afterEvaluate {
if (project.artifactId != project.name) {
println 'Artifact id: ' + project.artifactId
}
}
}
subprojects {
// Shared repositories:
repositories {
// Contains the locally built CraftBukkit and Spigot server dependencies.
mavenLocal()
mavenCentral()
// Bukkit, Spigot-API
maven { url 'https://hub.spigotmc.org/nexus/content/groups/public/' }
}
// Shared plugin / task configurations:
project.plugins.withId('java-library') {
java {
sourceCompatibility = JavaVersion.VERSION_1_8
}
// Configure all JavaCompile tasks (compileJava, compileTestJava, etc):
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.compilerArgs += ['-Xmaxerrs', '10000', '-Xmaxwarns', '10000']
}
processResources {
from rootProject.file('LICENSE')
from project.sourceSets.main.resources.srcDirs
// TODO Some plugins might add resource directories twice.
// See https://github.com/gradle/gradle/issues/17236
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
jar { jarTask ->
afterEvaluate {
configureJarTaskWithMavenMetadata(project, jarTask)
}
}
test {
systemProperty 'file.encoding', 'UTF-8'
workingDir project.file("${project.buildDir}/test-work/")
// Gradle complains when this folder does not yet exist.
doFirst {
workingDir.mkdirs()
}
}
}
project.plugins.withId('org.checkerframework') {
dependencies {
compileOnly libs.checkerframework.qual
checkerFramework libs.checkerframework.checker
testImplementation libs.checkerframework.qual
}
checkerFramework {
// TODO: Disabled because of lots false-positives after the update from 3.21.2 to 3.43.0.
skipCheckerFramework = true
checkers = [
'org.checkerframework.checker.nullness.NullnessChecker'
]
extraJavacArgs = [
'-AassumeAssertionsAreEnabled'
//'-AsuppressWarnings=initialization'
]
}
}
project.plugins.withId('maven-publish') {
// The maven-publish plugin does not generate the 'pom.properties' file. In order to mimic a
// normal Maven artifact, this task can be used to generate the properties file ourselves.
task generateMavenPomPropertiesFile {
File directory = new File("${buildDir}/mavenProperties/")
File outputFile = new File(directory, 'pom.properties')
afterEvaluate {
inputs.property 'group', project.group
inputs.property 'artifactId', project.artifactId
inputs.property 'version', project.version
outputs.file outputFile
}
doLast {
directory.mkdirs()
outputFile.text = "" +
"groupId=${project.group}\n" +
"artifactId=${project.artifactId}\n" +
"version=${project.version}\n"
}
}
publishing {
repositories {
// Formerly nexus.cube-nation.de, nexus.lichtspiele.org
// Contact person: Kronox (Discord); formerly: d1rty (dbo: d1rtyseven)
maven {
name 'projectshard'
credentials {
username findProperty('dev.projectshard.repo-username') ?: 'UNSET'
password findProperty('dev.projectshard.repo-password') ?: 'UNSET'
}
if (project.isSnapshot) {
url 'https://repo.projectshard.dev/repository/snapshots/'
} else {
url 'https://repo.projectshard.dev/repository/releases/'
}
}
}
}
}
}
// Predefined task list aliases:
// Minimal build: Quicker build that skips building any Spigot dependencies and only builds the API
// project. For example used for building on Jitpack, because we run into issues if:
// 1) The build takes too long.
// 2) We try to build Spigot. For some reason, Jitpack does not find our Shopkeepers artifacts then,
// even though they are correctly installed in the local Maven repository.
def taskListAliases = [
'cleanAssemble' : ['clean', 'assemble'],
'cleanBuild' : ['clean', 'build'],
'cleanInstall' : ['clean', 'build', 'publishToMavenLocal'],
'cleanPublish' : ['clean', 'build', 'publishToMavenLocal', 'publishAllPublicationsToProjectshardRepository'],
'cleanInstallMinimal' : ['clean', ':shopkeepers-api:publishToMavenLocal']
]
gradle.startParameter.taskNames = gradle.startParameter.taskNames.collect {
taskListAliases[it] ?: it
}.flatten()
println "Expanded task list: ${gradle.startParameter.taskNames}"