-
Notifications
You must be signed in to change notification settings - Fork 45
/
build.gradle
316 lines (275 loc) · 10.7 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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
}
plugins {
id "org.sonarqube" version "3.4.0.2513"
id 'com.github.kt3k.coveralls' version '2.12.0'
id 'groovy'
id 'jacoco'
id 'maven-publish'
id 'signing'
}
if(JavaVersion.current() != JavaVersion.VERSION_17 && JavaVersion.current() != JavaVersion.VERSION_21) {
throw new GradleException("This project requires Java 17 or Java 21, but it's running on "+JavaVersion.current())
}
/*
Groovy 2.4.21 supports bytecode Java 1.8 and lower. Do not use higher
bytecode values else it will default to Java 1.5. Jenkins would need to
upgrade core version of Groovy before higher bytecode versions are
available.
https://github.com/groovy/GMavenPlus/issues/256
*/
compileJava {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
compileGroovy {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
group = 'net.gleske'
archivesBaseName = 'jervis'
version = "${version}"
ext.groovyVersion = System.getenv('GROOVY_VERSION')?: '2.4.21'
ext.ossrhUsername = hasProperty('ossrhUsername')?project['ossrhUsername']:''
ext.ossrhPassword = hasProperty('ossrhPassword')?project['ossrhPassword']:''
ext.snakeYamlVersion = '2.2'
ext.bouncyCastleVersion = '1.75'
ext.codeNarcVersion = '3.2.0'
//if(JavaVersion.current() == JavaVersion.VERSION_17 && Integer.parseInt(ext.groovyVersion.tokenize('.').first()) < 3) {
// throw new GradleException("When using Java 17 you must use Groovy 3 or higher. Found Groovy " + ext.groovyVersion)
//}
if(Integer.parseInt(ext.groovyVersion.tokenize('.').first()) > 3) {
// Groovy 4 and higher
ext.groovyPackage = 'org.apache.groovy'
} else {
ext.groovyPackage = 'org.codehaus.groovy'
}
apply from: 'file:gradle/groovydoc.gradle'
apply from: 'file:gradle/jervis.gradle'
println "Using Groovy ${groovyVersion}"
println "Using Java ${org.gradle.internal.jvm.Jvm.current()}"
println "Building ${archivesBaseName}-${version}"
repositories {
mavenCentral()
}
// Address security vulnerability identified by DependencyTrack located as a
// transitive dependency within groovy-ant.
/*configurations.all {
resolutionStrategy {
dependencySubstitution {
substitute module('org.apache.ant:ant:1.9.15') with module('org.apache.ant:ant:1.9.16')
substitute module('org.apache.ant:ant-antlr:1.9.15') with module('org.apache.ant:ant-antlr:1.9.16')
substitute module('org.apache.ant:ant-junit:1.9.15') with module('org.apache.ant:ant-junit:1.9.16')
}
}
}*/
dependencies {
//implementation "${groovyPackage}:groovy-all:${groovyVersion}"
implementation "${groovyPackage}:groovy-ant:${groovyVersion}"
implementation "${groovyPackage}:groovy-groovydoc:${groovyVersion}"
implementation "${groovyPackage}:groovy-json:${groovyVersion}"
implementation "${groovyPackage}:groovy-templates:${groovyVersion}"
implementation "${groovyPackage}:groovy:${groovyVersion}"
implementation "org.bouncycastle:bcpkix-jdk18on:${bouncyCastleVersion}"
implementation "org.yaml:snakeyaml:${snakeYamlVersion}"
testImplementation 'junit:junit:4.13.2'
testImplementation "${groovyPackage}:groovy-test:${groovyVersion}"
testImplementation "${groovyPackage}:groovy-console:${groovyVersion}"
if(groovyVersion.tokenize('.').first() == '4') {
testImplementation "org.codenarc:CodeNarc:${codeNarcVersion}-groovy-4.0"
} else {
testImplementation "org.codenarc:CodeNarc:${codeNarcVersion}"
}
// CodeNarc throws stderr messages about SLF4J so this dependency makes the
// stderr go away.
testImplementation 'org.slf4j:slf4j-nop:2.0.5'
}
test {
// show standard out and standard error of the test JVM(s) on the console
testLogging.showStandardStreams = true
// set heap size for the test JVM(s)
minHeapSize = '128m'
maxHeapSize = '512m'
// listen to events in the test execution lifecycle
beforeTest { descriptor ->
logger.lifecycle('Running test: ' + descriptor)
}
// listen to standard out and standard error of the test JVM(s)
onOutput { descriptor, event ->
logger.lifecycle('Test: ' + descriptor + ' produced standard out/err: ' + event.message )
}
}
//https://github.com/s992/gatsby-blog/blob/master/src/content/posts/2014-07-17-running-the-groovy-console-from-gradle/index.md
task( console, dependsOn: "classes", type: JavaExec ) {
mainClass = "groovy.ui.Console"
classpath = sourceSets.main.runtimeClasspath + sourceSets.test.runtimeClasspath
}
task( update_vscode, dependsOn: "classes" ) {
doLast {
String classpath = (sourceSets.main.runtimeClasspath + sourceSets.test.runtimeClasspath).asPath
Map launch = (new groovy.json.JsonSlurper()).parseText(new File('.vscode/launch.json').text)
launch.configurations[0].classPaths = classpath.tokenize(':')
new File('.vscode/launch.json').withWriter('UTF-8') { writer ->
writer << groovy.json.JsonOutput.prettyPrint((launch as groovy.json.JsonBuilder).toString())
}
}
}
//Maven Central uploads
task javadocJar(type: Jar, dependsOn: groovydoc) {
archiveClassifier = 'javadoc'
from groovydoc.destinationDir
}
task testJar(type: Jar, dependsOn: testClasses) {
archiveClassifier = 'tests'
includes = ['net/gleske/**/*.class']
excludes = ['*.json', 'mocks/**/*', '**/*Test$_*.class', '**/*Test.class']
from sourceSets.test.output
}
task testSourcesJar(type: Jar) {
archiveClassifier = 'tests-sources'
includes = ['net/gleske/**/*.groovy']
excludes = ['**/*Test.groovy']
from sourceSets.test.allSource
}
artifacts {
archives javadocJar, testJar, testSourcesJar
}
jar {
manifest {
attributes 'Library-Name': rootProject.name,
'Library-Version': version,
'Library-Source': 'https://github.com/samrocketman/jervis',
'Library-Git-Hash': ['git', 'rev-parse', 'HEAD'].execute()?.text?.trim()
}
}
publishing {
repositories {
maven {
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
credentials {
username = ossrhUsername
password = ossrhPassword
}
}
}
publications {
binary(MavenPublication) {
from components.java
}
binaryAndSources(MavenPublication) {
from components.java
artifact javadocJar
artifact testJar
artifact testSourcesJar
pom {
name = 'Jervis'
packaging = 'jar'
// optionally artifactId can be defined here
description = 'Self service Jenkins job generation using Jenkins Job DSL plugin groovy scripts. Reads .jervis.yml and generates a job in Jenkins.'
url = 'https://github.com/samrocketman/jervis'
licenses {
license {
name = 'Apache License, Version 2.0'
url = 'https://raw.githubusercontent.com/samrocketman/jervis/main/LICENSE'
}
}
developers {
developer {
id = 'sag47'
name = 'Sam Gleske'
email = 'sam.mxracer@gmail.com'
}
}
scm {
connection = 'https://github.com/samrocketman/jervis.git'
developerConnection = 'git@github.com:samrocketman/jervis.git'
url = 'https://github.com/samrocketman/jervis'
}
}
}
}
}
// ./gradlew publish
tasks.withType(PublishToMavenRepository) {
onlyIf("publishing to maven central") {
publication == publishing.publications.binaryAndSources
}
}
// ./gradlew publishToMavenLocal
tasks.withType(PublishToMavenLocal) {
onlyIf("publishing only jar") {
publication == publishing.publications.binary
}
}
// signing must go after publishing block
signing {
required { gradle.taskGraph.hasTask("uploadArchives") && !gradle.taskGraph.hasTask("uploadArchives") }
def signingKey = findProperty("signingKey")
def signingPassword = findProperty("signingPassword")
useInMemoryPgpKeys(signingKey, signingPassword)
//sign configurations.archives
sign publishing.publications.binaryAndSources
}
// disable Gradle metadata in maven publishing
tasks.withType(GenerateModuleMetadata) {
enabled = false
}
//dependencies for building a jar
jar.dependsOn tasks.findAll { task -> task.name.endsWith('Jar') }
//disable optimizations for accurate branch coverage
//https://pbetkier.github.io/2014/08/07/groovy-code-coverage-issues.html
gradle.taskGraph.whenReady { graph ->
if(graph.hasTask(':test')) {
compileTestGroovy.groovyOptions.configurationScript = file('gradle/groovyTestCompilerConfig.groovy')
}
if(graph.hasTask(':jacocoTestReport')) {
compileGroovy.groovyOptions.optimizationOptions.all = false
}
if(graph.hasTask(':publish')) {
if(!(System.getenv('ORG_GRADLE_PROJECT_signingKey') && System.getenv('ORG_GRADLE_PROJECT_signingPassword'))) {
throw new GradleException("ERROR: Attempting to release without signing key and password. See RELEASE.md for details.")
}
}
}
jacocoTestReport {
reports {
csv.required = false
xml {
required = true
outputLocation = file("${buildDir}/test-results/jacoco.xml")
}
html.outputLocation = file("${buildDir}/reports/jacoco")
}
if(!findProperty('betaCoverage')) {
afterEvaluate {
classDirectories.from = files(classDirectories.files.collect {
fileTree(dir: it, exclude: '**/beta/**')
})
}
}
}
coveralls {
jacocoReportPath 'build/test-results/jacoco.xml'
}
// sonarqube integration
sonarqube {
properties {
//property "sonar.projectKey", "jervis"
//property "sonar.projectName", "jervis"
property "sonar.coverage.jacoco.xmlReportPaths", "${buildDir}/test-results/jacoco.xml"
if(!findProperty('betaCoverage')) {
property "sonar.coverage.exclusions", "**/beta/**"
}
}
}
project.tasks["jacocoTestReport"].dependsOn "check"
project.tasks["sonarqube"].dependsOn "jacocoTestReport"
project.tasks["coveralls"].dependsOn "jacocoTestReport"
//http://www.gradle.org/docs/current/userguide/gradle_wrapper.html
//generate gradlew with: ./gradlew wrapper --gradle-version 7.6