-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild.gradle
231 lines (195 loc) · 7.3 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
import java.time.Duration
/**
* In addition to releasing the library on Maven Central, we also release a SAS library along with some macros.
* Since the release is triggered on GitHub via the creation of a release, the SAS zip distribution has to be
* manually created before and added to the release:
*
* gradlew clean createDistribution
*
* Note that creating a release doesn't seem to trigger the publish job, I am not sure why. I have been doing it manually so far...
*/
plugins {
id 'java-library'
id 'checkstyle'
id 'jacoco'
id 'com.github.spotbugs' version '6.0.26'
id 'maven-publish'
id 'signing'
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0' // publish to Maven Central
id 'com.github.ben-manes.versions' version '0.51.0' // check for out-of-date dependencies (run 'dependencyUpdates' manually)
id 'org.sonatype.gradle.plugins.scan' version '2.8.3' // scan for vulnerabilities
id "org.sonarqube" version "5.1.0.4882"// sonarQube analysis
}
group = 'com.imsweb'
version = file('VERSION').text
description = 'This library provides support for the NAACCR XML format.'
println "Starting build using JDK ${Runtime.version().feature()}"
repositories {
mavenCentral()
}
dependencies {
api 'com.thoughtworks.xstream:xstream:1.4.21'
implementation 'commons-io:commons-io:2.17.0'
implementation 'org.apache.commons:commons-lang3:3.17.0'
testImplementation 'junit:junit:4.13.2'
testImplementation 'com.imsweb:data-generator:1.34'
testImplementation 'com.imsweb:layout:5.7'
testImplementation 'de.siegmar:fastcsv:3.4.0'
}
// enforce UTF-8, display the compilation warnings
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.compilerArgs << '-Xlint:unchecked' << '-Xlint:deprecation'
}
// the Javadoc was made way too strict in Java 8 and it's not worth the time fixing everything!
tasks.withType(Javadoc).configureEach {
options.addStringOption('Xdoclint:none', '-quiet')
}
// generate javadoc and sources (required by Nexus)
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
withJavadocJar()
withSourcesJar()
}
// I have absolutely no idea why I need to do this; it appears the test task depends on the created JAR file; I know it depends
// on the source code, but I can't figure out why it depends on the created archive itself. I found this workaround online...
tasks.named("test") {
dependsOn(tasks.named("jar"))
}
// customize the manifest
jar {
manifest {
attributes('Implementation-Title': project.name,
'Implementation-Version': project.version,
'Implementation-Vendor': 'Information Management Services Inc.',
'Created-By': System.properties['java.vm.version'] + ' (' + System.properties['java.vm.vendor'] + ')',
'Built-By': System.getProperty('user.name'),
'Built-Date': new Date(),
'Built-JDK': System.getProperty('java.version'),
'Automatic-Module-Name': 'com.imsweb.naaccrxml')
}
from('VERSION') {
rename 'VERSION', 'NAACCR-XML-VERSION'
}
from('LICENSE') {
rename 'LICENSE', 'NAACCR-XML-LICENSE'
}
}
sonarqube {
properties {
property "sonar.projectKey", "imsweb_naaccr-xml"
property "sonar.organization", "imsweb"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.exclusions", "**/lab/**,**/sas/**"
property "sonar.coverage.exclusions", "**/lab/**,**/sas/**"
}
}
// Nexus vulnerability scan (see https://github.com/sonatype-nexus-community/scan-gradle-plugin)
ossIndexAudit {
outputFormat = 'DEPENDENCY_GRAPH'
printBanner = false
}
check.dependsOn 'ossIndexAudit'
// checkstyle plugin settings
checkstyle {
ignoreFailures = false
configFile = project(':').file('config/checkstyle/checkstyle.xml')
configProperties = ['suppressionFile': project(':').file('config/checkstyle/checkstyle-exclude.xml')]
}
// spotbugs plugin settings
spotbugs {
ignoreFailures = false
excludeFilter.set(project(':').file("config/spotbugs/spotbugs-exclude.xml"))
}
jacocoTestReport {
reports {
xml.required = true
}
}
test.finalizedBy jacocoTestReport
def isNonStable = { String version ->
def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { it -> version.toUpperCase().contains(it) }
def regex = /^[0-9,.v-]+(-r)?$/
return !stableKeyword && !(version ==~ regex)
}
// https://github.com/ben-manes/gradle-versions-plugin
tasks.named("dependencyUpdates").configure {
rejectVersionIf {
isNonStable(it.candidate.version)
}
}
// needed to deploy to Maven Central
publishing {
publications {
mavenJava(MavenPublication) {
artifactId = 'naaccr-xml'
from components.java
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
pom {
name = 'NAACCR XML'
description = 'This library provides support for the NAACCR XML format.'
url = 'https://github.com/imsweb/naaccr-xml'
inceptionYear = '2015'
licenses {
license {
name = 'A modified BSD License (BSD)'
url = 'https://github.com/imsweb/naaccr-xml/blob/master/LICENSE'
distribution = 'repo'
}
}
developers {
developer {
id = 'depryf'
name = 'Fabian Depry'
email = '[email protected]'
}
}
scm {
url = 'https://github.com/imsweb/naaccr-xml'
connection = 'scm:https://github.com/imsweb/naaccr-xml.git'
developerConnection = 'scm:[email protected]:imsweb/naaccr-xml.git'
}
}
}
}
}
// setup JAR signing
signing {
required { !project.version.endsWith('-SNAPSHOT') }
String signingKey = project.findProperty('signingKey') ?: ''
String signingPassword = project.findProperty('signingPassword') ?: ''
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications.mavenJava
}
// needed to release on maven central
nexusPublishing {
repositories {
sonatype {
stagingProfileId = '63e5ddd3ab0d16'
username = project.findProperty("nexusUsername")
password = project.findProperty("nexusPassword")
}
}
clientTimeout = Duration.ofSeconds(300)
connectTimeout = Duration.ofSeconds(60)
transitionCheckOptions {
maxRetries.set(50)
delayBetween.set(Duration.ofMillis(5000))
}
}
// Gradle wrapper, this allows to build the project without having to install Gradle...
wrapper {
gradleVersion = '8.11'
distributionType = Wrapper.DistributionType.ALL
}
// the SAS library is compiled under Java 8 code-compatibility; Intellij can't handle that (only because I didn't properly set it up as a module)
if (System.getProperty("idea.active") != 'true')
apply from: 'gradle/sas.gradle'