/
build.gradle
369 lines (322 loc) · 12.9 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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
import org.apache.tools.ant.taskdefs.condition.Os
import org.apache.tools.ant.filters.*
plugins {
id 'com.github.spotbugs' version '5.0.6' apply false
id "io.freefair.lombok" version "6.4.3" apply false
id 'org.owasp.dependencycheck' version '6.5.3' apply false
id "org.gradle.test-retry" version "1.3.2" apply false
}
ext {
interlokCoreVersion = project.findProperty('interlokCoreVersion') ?: '4.5-SNAPSHOT'
releaseVersion = project.findProperty('releaseVersion') ?: '4.5-SNAPSHOT'
nexusBaseUrl = project.findProperty('nexusBaseUrl') ?: 'https://nexus.adaptris.net/nexus'
mavenPublishUrl = project.findProperty('mavenPublishUrl') ?: nexusBaseUrl + '/content/repositories/snapshots'
javadocsBaseUrl = nexusBaseUrl + "/content/sites/javadocs/com/adaptris"
repoUsername = project.findProperty('repoUsername') ?: 'unknown'
repoPassword = project.findProperty('repoPassword') ?: 'unknown'
defaultNexusRepo = project.findProperty('defaultNexusRepo') ?: 'unknown'
interlokJavadocs= project.findProperty('interlokJavadocs') ?: javadocsBaseUrl + "/interlok-core/" + interlokCoreVersion
interlokCommonJavadocs= project.findProperty('interlokCommonJavadocs') ?: javadocsBaseUrl + "/interlok-common/" + interlokCoreVersion
offlineJavadocPackageDir = new File(project.buildDir, "offline-javadoc-packages")
organizationName = "Adaptris Ltd"
organizationUrl = "http://interlok.adaptris.net"
slf4jVersion = '1.7.36'
mockitoVersion = '4.5.0'
junitJupiterVersion = '5.8.2'
}
ext.buildDetails = [
hostname: { ->
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
return System.getenv("COMPUTERNAME")
}
return System.getenv("HOSTNAME")
},
gitBranchNameOrTimestamp: { branchName ->
if (branchName.equals("HEAD") || branchName.equals("develop") || branchName.startsWith("release")) {
return new Date().format('HH:mm:ss z');
}
return branchName;
},
buildInfo: { ->
new ByteArrayOutputStream().withStream { os ->
exec {
executable = "git"
args = ["rev-parse", "--abbrev-ref", "HEAD"]
standardOutput = os
}
def branchName = os.toString().replaceAll("\r", "").replaceAll("\n", "").trim();
return buildDetails.gitBranchNameOrTimestamp(branchName);
}
},
// If graphviz is installed via scoop, plantuml doesn't find it because it's not
// in its expected "location(s)" it searches for c:\*\graphviz**\dot.exe
// so windows we'd expect to have the GRAPHVIZ_DOT env defined
// On Linux we should be able to find it via the path.
hasGraphViz: { ->
def app = "dot"
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
app = app + ".exe"
}
return System.getenv("GRAPHVIZ_DOT") !=null || System.getenv("PATH").split(File.pathSeparator).any{
java.nio.file.Paths.get("${it}").resolve(app).toFile().exists()
}
},
propertyTemplate: { dir, filename ->
def file = new File(dir, filename + "." + buildDetails.hostname())
if (file.exists()) {
return file.getName()
}
return filename
},
is_ci_pipeline: { ->
return System.getenv().containsKey("CI");
}
]
// Disable gradle module generation since we probably don't want
// xxx.module files in your repository.
allprojects {
tasks.withType(Jar) {
metaInf {
from ("$rootDir") {
include 'LICENSE*'
include 'NOTICE*'
}
}
}
tasks.withType(GenerateModuleMetadata) {
enabled = false
}
}
task clean(type: Delete) {
delete project.buildDir
}
subprojects {
// Apply the java plugin to add support for Java
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: "jacoco"
apply plugin: "io.freefair.lombok"
apply plugin: 'com.github.spotbugs'
apply plugin: 'org.owasp.dependencycheck'
apply plugin: 'org.gradle.test-retry'
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
group = 'com.adaptris'
version = releaseVersion
def versionDir = "$buildDir/version"
lombok.disableConfig = true
repositories {
mavenCentral() {
content {
excludeGroupByRegex "com\\.adaptris.*"
}
}
if (defaultNexusRepo != "unknown") {
maven {
url "$defaultNexusRepo"
allowInsecureProtocol true
}
}
maven { url "$nexusBaseUrl/content/groups/public" }
maven { url "$nexusBaseUrl/content/groups/interlok" }
}
configurations {
javadoc {}
umlDoclet {}
offlineJavadocPackages {}
all*.exclude group: 'c3p0'
all*.exclude group: 'commons-logging'
all*.exclude group: 'javamail'
all*.exclude group: 'javax.mail', module: 'mail'
all*.exclude group: 'org.glassfish.hk2.external'
all*.exclude group: 'xalan', module: 'xalan'
all*.exclude group: 'net.sf.saxon', module: 'saxon'
all*.exclude group: 'org.codehaus.woodstox'
all*.exclude group: 'org.eclipse.jetty.orbit', module: 'javax.mail.glassfish'
// INTERLOK-3197 exclude old javax.mail
all*.exclude group: 'com.sun.mail', module: 'javax.mail'
all*.exclude group: 'javax.validation', module: 'validation-api'
all*.exclude group: 'javax.activation', module: 'activation'
all*.exclude group: 'javax.activation', module: 'javax.activation-api'
// INTERLOK-3740 switch from jcraft to com.github.mwiede jsch fork.
all*.exclude group: 'com.jcraft', module: 'jsch'
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, "seconds"
}
dependencies {
api ("com.adaptris:interlok-core:$interlokCoreVersion") { changing= true}
api ("com.adaptris:interlok-core-apt:$interlokCoreVersion") { changing= true}
implementation ("org.slf4j:slf4j-api:$slf4jVersion")
implementation ("org.slf4j:jcl-over-slf4j:$slf4jVersion")
annotationProcessor ("com.adaptris:interlok-core-apt:$interlokCoreVersion") { changing= true}
testImplementation ('junit:junit:4.13.2')
testImplementation ("com.adaptris:interlok-stubs:$interlokCoreVersion") { changing= true }
testImplementation ("org.mockito:mockito-core:$mockitoVersion")
testImplementation ("org.mockito:mockito-inline:$mockitoVersion")
testImplementation ("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion")
testImplementation ("org.junit.jupiter:junit-jupiter:$junitJupiterVersion")
testRuntimeOnly ("org.slf4j:slf4j-simple:$slf4jVersion")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:$junitJupiterVersion") {
because 'allows JUnit 3 and JUnit 4 tests to run'
}
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.8.2") {
because 'allows tests to run from IDEs that bundle older version of launcher'
}
javadoc("com.adaptris:interlok-core-apt:$interlokCoreVersion") { changing= true}
offlineJavadocPackages ("com.adaptris:interlok-core:$interlokCoreVersion:javadoc@jar") { changing= true}
offlineJavadocPackages ("com.adaptris:interlok-common:$interlokCoreVersion:javadoc@jar") { changing= true}
umlDoclet("nl.talsmasoftware:umldoclet:2.0.14")
}
javadoc {
onlyIf {
!buildDetails.hasGraphViz()
}
configure(options) {
options.linksOffline(interlokJavadocs, offlineJavadocPackageDir.getCanonicalPath() + "/interlok-core-$interlokCoreVersion-javadoc.jar")
options.linksOffline(interlokCommonJavadocs, offlineJavadocPackageDir.getCanonicalPath() + "/interlok-common-$interlokCoreVersion-javadoc.jar")
taglets = ["com.adaptris.taglet.ConfigTaglet", "com.adaptris.taglet.LicenseTaglet"]
options.addStringOption "tagletpath", configurations.javadoc.asPath
options.addBooleanOption "-no-module-directories", true
options.addStringOption('Xdoclint:none', '-quiet')
}
}
task umlJavadoc(type: Javadoc) {
group 'Documentation'
description 'Build javadocs using plantuml + graphviz + umldoclet, if dot is available'
onlyIf {
buildDetails.hasGraphViz()
}
source = sourceSets.main.extensions.delombokTask
classpath = project.sourceSets.main.compileClasspath
configure(options) {
options.linksOffline(interlokJavadocs, offlineJavadocPackageDir.getCanonicalPath() + "/interlok-core-$interlokCoreVersion-javadoc.jar")
options.linksOffline(interlokCommonJavadocs, offlineJavadocPackageDir.getCanonicalPath() + "/interlok-common-$interlokCoreVersion-javadoc.jar")
taglets = ["com.adaptris.taglet.ConfigTaglet", "com.adaptris.taglet.LicenseTaglet"]
options.addStringOption "tagletpath", configurations.javadoc.asPath
options.addStringOption "Xdoclint:none", "-quiet"
options.addBooleanOption "-no-module-directories", true
options.docletpath = configurations.umlDoclet.files.asType(List)
options.doclet = "nl.talsmasoftware.umldoclet.UMLDoclet"
// Create class & package use pages
options.addStringOption "use"
options.addStringOption "umlImageFormat", "SVG"
options.addStringOption "umlExcludedTypeReferences", "java.lang.Exception,java.lang.Object,java.lang.Enum,java.lang.annotation.Annotation"
options.addStringOption "umlJavaBeanPropertiesAsFields"
options.addBooleanOption "failOnCyclicPackageDependencies", false
}
}
jacocoTestReport {
reports {
xml.required= true
html.required= true
}
}
sourceSets {
main {
output.dir(versionDir, builtBy: 'generateVersion')
}
}
// Generate the META-INF/adaptris-version file
task generateVersion {
doLast {
def versionFile = new File(new File(versionDir, 'META-INF'), 'adaptris-version')
versionFile.getParentFile().mkdirs()
ant.propertyfile(file: versionFile) {
entry(key: 'component.name', value: componentName)
entry(key: 'component.description', value: componentDesc)
entry(key: 'groupId', value: project.group)
entry(key: 'artifactId', value: project.name)
entry(key: 'build.version', value: releaseVersion)
entry(key: 'build.date', value: new Date().format('yyyy-MM-dd'))
entry(key: 'build.info', value: buildDetails.buildInfo())
}
}
}
task offlinePackageList(type: Copy) {
description 'Build an offline package-list for javadocs'
group 'Documentation'
project.configurations.offlineJavadocPackages.collect { dependency ->
from(zipTree(dependency)) {
into dependency.name
}
}
include "package-list"
include "element-list"
into offlineJavadocPackageDir
}
ext.testResourcesDir = { ->
return "${project.projectDir}/src/test/resources".replaceAll("\\\\", "/")
}
task generateUnitTestProperties {
doLast {
def testResourcesDir = testResourcesDir()
ant.property(file: project.projectDir.getCanonicalPath() + "/" + "build.properties")
ant.property(file: testResourcesDir + "/" + buildDetails.propertyTemplate(testResourcesDir, "unit-tests.properties.template"))
ant.echoproperties(destfile: testResourcesDir + '/unit-tests.properties.resolved', prefix: "junit.")
ant.replace(file: testResourcesDir + '/unit-tests.properties.resolved', token:"junit.", value: "")
}
}
task copyUnitTestProperties() {
dependsOn(generateUnitTestProperties)
doLast {
def testResourcesDir = testResourcesDir()
delete file( testResourcesDir + '/unit-tests.properties')
ant.copy(file: testResourcesDir + "/unit-tests.properties.resolved",
tofile: testResourcesDir + '/unit-tests.properties') {
filterset {
filter(token: "JAVA_HOME", value: System.getProperty("java.home").replaceAll("\\\\", "/"))
filter(token: "BASE_DIR", value: project.projectDir.getCanonicalPath().replaceAll("\\\\", "/"))
filter(token: "BUILD_DIR", value: project.buildDir.getCanonicalPath().replaceAll("\\\\", "/"))
}
}
}
}
spotbugsMain {
effort = "max"
reportLevel = "high"
reports {
xml {
required.set(false)
}
html {
required.set(true)
stylesheet = 'default.xsl'
}
}
}
// disable spotbugsTests which checks our test code..
spotbugsTest.enabled = false
dependencyCheck {
suppressionFiles= [ "https://raw.githubusercontent.com/adaptris/interlok/develop/gradle/owasp-exclude.xml" , "$rootDir/gradle/owasp-exclude.xml" ]
scanConfigurations = [ "api", "compileClasspath", "runtimeClasspath" ]
formats = [ "HTML", "JUNIT" ]
junitFailOnCVSS = 7.0
failBuildOnCVSS = 7.0
analyzers {
assemblyEnabled=false
}
}
task lgtmCompile(type: JavaCompile, dependsOn: delombok) {
group 'Build'
description 'Compile for lgtm'
source = sourceSets.main.extensions.delombokTask
destinationDirectory= sourceSets.main.java.classesDirectory
classpath = project.sourceSets.main.compileClasspath
}
test {
if (buildDetails.is_ci_pipeline()) {
retry {
maxRetries = 3
maxFailures = 20
}
}
useJUnitPlatform()
}
lombok {
version = "1.18.22"
}
javadoc.dependsOn offlinePackageList,umlJavadoc
check.dependsOn jacocoTestReport
}