-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild.gradle
298 lines (245 loc) · 8.21 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
//
// build.gradle
//
buildscript {
ext {
slf4jVersion = "1.7.36"
logbackVersion = "1.2.11"
groovyVersion = "3.0.9"
spockVersion = "2.1-groovy-3.0"
nettyVersion = "4.1.76.Final"
springBootVersion = "1.5.20.RELEASE"
springCloudVersion = "Edgware.SR5"
jdkByteCodeVersion = "1.8"
}
}
plugins {
id "java-library"
id "net.researchgate.release" version "2.8.1"
id "io.spring.dependency-management" version "1.0.11.RELEASE"
id "com.adarshr.test-logger" version "3.2.0"
id "io.franzbecker.gradle-lombok" version "5.0.0"
id "com.fizzpod.sweeney" version "4.4.0"
// non-applied plugins
id "com.gorylenko.gradle-git-properties" version "2.4.0" apply false
id "com.github.johnrengelman.shadow" version "7.1.2" apply false
}
ext.isReleaseVersion = !version.contains("-SNAPSHOT")
def getProjectProp(name, defaultValue) {
if (project.hasProperty(name)) {
return project.getProperties().get(name)
}
// consult env vars
def envVarName = name.toUpperCase().replace(".", "_")
def envVarValue = System.getenv(envVarName)
return (envVarValue) ? envVarValue : defaultValue
}
allprojects {
apply plugin: "java-library"
apply plugin: "groovy"
apply plugin: "idea"
apply plugin: "eclipse"
apply plugin: "maven-publish"
apply plugin: "signing"
apply plugin: "io.spring.dependency-management"
apply plugin: "com.adarshr.test-logger"
repositories {
mavenLocal()
mavenCentral()
}
dependencyManagement {
imports {
mavenBom "io.netty:netty-bom:${nettyVersion}"
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
mavenBom "org.spockframework:spock-bom:${spockVersion}"
}
dependencies {
dependency "org.codehaus.groovy:groovy-all:${groovyVersion}"
// logging
dependency "org.slf4j:slf4j-api:${slf4jVersion}"
dependency "org.slf4j:jcl-over-slf4j:${slf4jVersion}"
dependency "ch.qos.logback:logback-classic:${logbackVersion}"
dependency "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
dependency "info.picocli:picocli:4.6.3"
}
}
// dependencies for all projects
dependencies {
// JDK11 compilation compatibility
compileOnly "javax.annotation:javax.annotation-api:1.3.2"
testImplementation "org.codehaus.groovy:groovy-all"
testImplementation "org.spockframework:spock-core"
testImplementation "ch.qos.logback:logback-classic"
}
// we ❤️❤️❤️ lombok!
apply plugin: "io.franzbecker.gradle-lombok"
lombok {
version = "1.18.22"
}
// enforce build rules
apply plugin: 'com.fizzpod.sweeney'
sweeney {
enforce "gradle:[7.4,)" // require gradle >= 7.4
enforce "jdk:[11,)" // require JDK11
}
plugins.withType(JavaPlugin) {
// java bytecode version
sourceCompatibility = "${jdkByteCodeVersion}"
targetCompatibility = "${jdkByteCodeVersion}"
// create jar only if there is something to package
boolean hasSources = !sourceSets.main.allSource.files.isEmpty()
jar {
onlyIf { hasSources }
}
// create sources jar
task sourcesJar(type: Jar, dependsOn: classes, overwrite: false) {
archiveClassifier = "sources"
from sourceSets.main.allJava
}
// javadoc options
javadoc {
options.encoding "UTF-8"
options.addStringOption("Xdoclint:none", "-quiet")
if (JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}
task javadocJar(type: Jar, dependsOn: [classes, javadoc], overwrite: false) {
from javadoc
archiveClassifier = "javadoc"
}
// add compileOnly dependencies to test runtime classpath as well.
sourceSets {
test.compileClasspath += configurations.compileClasspath
test.runtimeClasspath += configurations.compileClasspath
}
// set publish repos only if there are any sources to publish
if (hasSources) {
publishing {
repositories {
maven {
def urlReleases = "https://oss.sonatype.org/content/repositories/snapshots/"
def urlSnapshots = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
url = isReleaseVersion ? urlSnapshots : urlReleases
credentials {
username getProjectProp('osshr.user', 'some-osshr-user')
password getProjectProp('osshr.pass', 'some-osshr-pass')
}
}
}
publications {
mavenJava(MavenPublication) {
from components.java
if (tasks.findByName("sourcesJar")) {
artifact sourcesJar
}
if (tasks.findByName("javadocJar")) {
artifact javadocJar
}
pom {
name = "Eureka DNS server"
description = "DNS server interface to Eureka service registry"
url = "https://github.com/bfg/eureka-dns-server/"
scm {
connection = "scm:git:https://github.com/bfg/eureka-dns-server.git"
developerConnection = "scm:git:https://github.com/bfg/eureka-dns-server.git"
url = "https://github.com/bfg/eureka-dns-server/"
}
licenses {
license {
name = "The Apache License, Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
developers {
developer {
id = "bfg"
name = "Brane F. Gračnar"
}
developer {
id = "github"
name = "Github project contributors"
url = "https://github.com/bfg/eureka-dns-server/graphs/contributors"
}
}
}
}
}
}
}
}
artifacts {
archives jar
archives sourcesJar
archives javadocJar
}
signing {
// fetch signing key from gpg-agent
// NOTE: don't forget to set gpg key id in `signing.gnupg.keyName` gradle property (~/.gradle.properties)
useGpgCmd()
// define what to sign
sign publishing.publications
}
tasks.withType(Sign) {
// only do gpg sign if there is key defined and this is a release build
onlyIf { isReleaseVersion && project.hasProperty('signing.gnupg.keyName') }
}
tasks.withType(JavaCompile) {
sourceCompatibility = targetCompatibility = "${jdkByteCodeVersion}"
options.incremental = true
//options.verbose = true
options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
}
tasks.withType(GroovyCompile) {
sourceCompatibility = targetCompatibility = "${jdkByteCodeVersion}"
//options.incremental = true
//options.verbose = true
options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
}
// required for successful spock test runtime execution
ext['groovy.version'] = "${groovyVersion}"
// reproducible builds
tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
test {
useJUnitPlatform()
failFast = true
}
testlogger {
theme "mocha"
slowThreshold 5000
}
}
subprojects {
apply plugin: "jacoco"
// BEGIN: jacoco test coverage
task copyJacocoReports(type: Copy, dependsOn: "jacocoTestReport") {
from "build/reports/jacoco/html"
into "$rootDir/build/reports/jacoco/${project.name}"
}
jacoco {
toolVersion = "0.8.8"
}
jacocoTestReport {
dependsOn test
reports {
xml.required = true
csv.required = false
html.outputLocation = layout.buildDirectory.dir('reports/jacoco/html')
}
}
test.finalizedBy copyJacocoReports
// END: jacoco
testResultsDirName = "$rootDir/build/junit"
reporting.baseDir = "$rootDir/build/html/${project.name}"
}
release {
git {
requireBranch = ""
}
}
// vim:shiftwidth=2 softtabstop=2 expandtab
// EOF