forked from MauroDataMapper/mdm-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
340 lines (301 loc) · 13.4 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
import java.awt.Desktop
import java.lang.management.ManagementFactory
import java.lang.management.RuntimeMXBean
import java.nio.file.Paths
import java.util.concurrent.TimeUnit
buildscript {
repositories {
mavenLocal()
maven {url 'https://jenkins.cs.ox.ac.uk/artifactory/plugins-snapshot'}
maven {url 'https://jenkins.cs.ox.ac.uk/artifactory/plugins-release'}
}
dependencies {
classpath "uk.ac.ox.softeng.maurodatamapper.gradle:mdm-gradle-plugin:$mdmGradlePluginVersion"
classpath "uk.ac.ox.softeng.maurodatamapper.gradle:mdm-gradle-plugin:$mdmGradlePluginVersion"
}
configurations.all {
// check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, TimeUnit.SECONDS
}
}
plugins {
id 'maven-publish'
id "org.sonarqube" version "3.3"
// The springboot plugin is loaded in by grails and if the version of the plugin isnt right it will override all versions of imported spring boot dependencies
// Therefore we can define it here (but not apply it to the root) and then ALL subprojects will use this version rather than another version
id 'org.springframework.boot' version "${springBootVersion}" apply false
}
apply plugin: 'ox.softeng.ox-brc-base'
task unitTest() {
group 'testing'
description = 'Catch task for unit test'
}
task integrationTest() {
group 'testing'
description = 'Catch task for integration test'
mustRunAfter unitTest
}
task jacocoRootReport() {
group 'reporting'
description = 'Catch task for all jacoco root report'
mustRunAfter unitTest, integrationTest
}
task staticCodeAnalysis() {
group 'reporting'
description = 'Catch task for all SCA tasks'
mustRunAfter unitTest, integrationTest, jacocoRootReport
}
check {
dependsOn unitTest, integrationTest, jacocoRootReport, staticCodeAnalysis
}
task('sysProps') {
group 'help'
doLast {
logger.quiet('{}', System.properties.collect {"${it.key}:${it.value}"}.sort().join('\n'))
}
}
task('jvmArgs') {
group 'help'
doLast {
RuntimeMXBean runtimeMxBean2 = ManagementFactory.getRuntimeMXBean()
logger.quiet('{}', runtimeMxBean2.getInputArguments().join('\n'))
}
}
task('jenkinsClean') {
group 'clean'
delete 'build'
}
logger.quiet(
"Available processors ${Runtime.runtime.availableProcessors()}. Max Unit Test Parallel Forks " +
"${Runtime.runtime.availableProcessors().intdiv(2) ?: 1}")
task rootTestReport(type: TestReport) {
group = 'reporting'
destinationDir = file("${buildDir}/reports/tests")
testResultDirs = files("${buildDir}/test-results")
FileCollection testResultContentDir = files("${buildDir}/test-results")
outputs.upToDateWhen {false}
doFirst {
(testResultContentDir.getAsFileTree().visit {FileVisitDetails details ->
if (details.directory && details.name == 'binary') {
logger.info("Reporting on ${details.path}")
reportOn files(details.file)
}
})
}
doLast {
if (Desktop.isDesktopSupported()) {
Desktop.desktop.open(Paths.get("${buildDir}/reports/tests/index.html").toFile())
} else {
logger.error("File opening not supported by JVM, use native OS command")
}
}
}
tasks.register('outputRuntimeArgs') {
doLast {
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean()
List<String> arguments = runtimeMxBean.getInputArguments()
logger.warn("Running with JVM args : {}", arguments.size())
Map<String, String> map = arguments.collectEntries {arg ->
arg.split('=').toList()
}.sort() as Map<String, String>
map.each {k, v ->
if (v) logger.quiet('{}={}', k, v)
else logger.quiet('{}', k)
}
}
}
tasks.register('outputIntegrationTestShell') {
doLast {
StringBuilder sb = new StringBuilder('./gradlew --build-cache -Dgradle.integrationTest=true \\')
subprojects.each {
if (it.name != 'mdm-testing-functional' &&
it.file('src/integration-test').exists()) sb.append('\n ').append(it.path).append(':integrationTest \\')
}
logger.quiet '{}', sb.toString()
}
}
tasks.register('outputFunctionalTestShell') {
doLast {
StringBuilder sb = new StringBuilder('./gradlew --build-cache -Dgradle.functionalTest=true \\')
subprojects.each {
if (it.name != 'mdm-testing-functional' &&
it.file('src/integration-test').exists()) sb.append('\n ').append(it.path).append(':integrationTest \\')
}
logger.quiet '{}', sb.toString()
}
}
tasks.register('outputE2ETestShell') {
doLast {
file('mdm-testing-functional/src/integration-test/groovy/uk/ac/ox/softeng/maurodatamapper/testing/functional').listFiles().each {f ->
logger.quiet './gradlew --build-cache -Dgradle.test.package={} :mdm-testing-functional:integrationTest', f.name
}
}
}
subprojects {
project.ext['mdmCoreVersion'] = version
tasks.register("bomProperties") {
group = 'Introspection'
description = 'Print properties from all BOMs'
doLast {
if (project.hasProperty('dependencyManagement')) {
Map imported = dependencyManagement.importedProperties
logger.quiet 'Project :: {}\nproperty,version,overriden_version\n{}', project.name, imported.collect {k, v ->
def projProp = project.hasProperty(k) ? project.getProperty(k) : project.hasProperty(k - '.version') ? project.getProperty(k - '.version') : null
"$k,$v,${projProp ?: ''}"
}.sort().join('\n')
}
}
}
tasks.register('copyTestResultsToRoot', Copy) {
from file("${project.buildDir}/test-results")
into file("${rootProject.buildDir}/test-results/${project.name}")
doFirst {
logger.quiet("Copying ${file("${project.buildDir}/test-results")} to ${file("${rootProject.buildDir}/test-results/${project.name}")}")
}
rootProject.rootTestReport.dependsOn it
}
afterEvaluate {
// This doubles down on making sure the imported and overridden properties from mdm-bom are properly enforced on all sub projects
if (project.name != 'mdm-bom') {
project.getRootProject().findProject(':mdm-bom').ext['controlledProperties'].each {k, v ->
project.ext[k] = v
}
}
// Dont bother with mergeTestReports if running in jenkins
if (project.tasks.findByName('mergeTestReports')) {
project.tasks.findByName('mergeTestReports').onlyIf {
!System.getenv().containsKey('JENKINS')
}
}
/*
To make the following work, tests or classes should be marked with the jupiter annotation @Tag
*/
if (project.tasks.findByName('integrationTest')) {
FileCollection nonParallelTestFiles = findNonParallelTestFiles(project)
if (project.ext.parallelTestingOnly) {
if (project.ext.itTestsAvailable) logger.log(LogLevel.WARN, '<<>> Running integration tests in parallel mode <<>>')
project.integrationTest {
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
useJUnitPlatform {
// TODO Once spock handles jupiter tags then we can use this and remove the filter
// excludeTags 'non-parallel'
}
filter {
nonParallelTestFiles.each {f ->
logger.log(LogLevel.WARN, 'Ignoring {}', f.name - '.groovy')
excludeTestsMatching("*${f.name - '.groovy'}")
}
}
binaryResultsDirectory.set(project.file("${project.testResultsDir}/parallelIntegrationTest/binary"))
reports {
junitXml.getOutputLocation().set project.file("${project.testResultsDir}/parallelIntegrationTest")
}
jacoco {
destinationFile = project.file("${project.buildDir}/jacoco/parallelIntegrationTest.exec")
}
}
project.mergeTestReports.reportOn(project.file("${project.testResultsDir}/parallelIntegrationTest/binary"))
} else if (project.ext.nonParallelTestingOnly) {
if (!nonParallelTestFiles.isEmpty()) logger.log(LogLevel.WARN, '<<>> Running integration tests in non-parallel mode <<>>')
project.integrationTest {
onlyIf {
!nonParallelTestFiles.isEmpty()
}
filter {
nonParallelTestFiles.each {f ->
logger.log(LogLevel.WARN, 'Testing {}', f.name - '.groovy')
includeTestsMatching("*${f.name - '.groovy'}")
}
}
maxParallelForks = 1
useJUnitPlatform {
// TODO Once spock handles jupiter tags then we can use this and remove the filter
// includeTags 'non-parallel'
}
binaryResultsDirectory.set(project.file("${project.testResultsDir}/nonParallelIntegrationTest/binary"))
reports {
junitXml.getOutputLocation().set project.file("${project.testResultsDir}/nonParallelIntegrationTest")
}
jacoco {
destinationFile = project.file("${project.buildDir}/jacoco/nonParallelIntegrationTest.exec")
}
}
project.mergeTestReports.reportOn(project.file("${project.testResultsDir}/nonParallelIntegrationTest/binary"))
}
}
if (project.name != 'mdm-bom') {
project.publishing {
publications {
mavenJar {
pom {
name = project.name
url = 'https://github.com/MauroDataMapper/mdm-core'
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'olliefreeman'
name = 'Oliver Freeman'
email = '[email protected]'
}
developer {
id = 'jameswelch'
name = 'James Welch'
email = '[email protected]'
}
}
scm {
connection = '[email protected]:MauroDataMapper/mdm-core.git'
developerConnection = '[email protected]:MauroDataMapper/mdm-core.git'
url = 'https://github.com/MauroDataMapper/mdm-core'
}
}
}
}
}
}
}
}
afterEvaluate {
/*
Massive hack to solve parallel task running for assetCompile task
Make sure that each task mustRunAfter another assetCompile task, this ensures none of them can run at the same time
We have to allow for project dependencies so make sure thats accounted for manually
*/
List<Task> assetCompileTasks = it.getTasksByName('assetCompile', true).toList().sort {it.path}
Task coreTask = assetCompileTasks.find {it.path.startsWith(':mdm-core')}
Task dataModelTask = assetCompileTasks.find {it.path.startsWith(':mdm-plugin-datamodel')}
assetCompileTasks.remove(coreTask)
assetCompileTasks.remove(dataModelTask)
// dataModelTask.mustRunAfter coreTask
assetCompileTasks.each {
it.mustRunAfter coreTask, dataModelTask
}
for (int i = 1; i < assetCompileTasks.size(); i++) {
assetCompileTasks[i].mustRunAfter assetCompileTasks[i - 1]
}
logger.quiet 'Project: {} > group: {}, version {}', project.name, project.group, project.version
}
Set<Project> collectProjectDependencies(Project project) {
Set<Project> dependencyProjects = new HashSet<>()
ConfigurationContainer configurations = project.configurations
Configuration configuration = configurations.findByName('implementation')
if (configuration) {
DomainObjectSet<ProjectDependency> projectDependencies = configuration.dependencies.withType ProjectDependency
projectDependencies.forEach {
dependencyProjects.add(it.dependencyProject)
dependencyProjects.addAll(collectProjectDependencies(it.dependencyProject))
}
}
dependencyProjects
}
FileCollection findNonParallelTestFiles(Project project) {
project.fileTree('src/integration-test/groovy').filter {File f ->
!f.name.find(/FunctionalSpec/) &&
f.text.find(/@Tag\('non-parallel'\)/)
}
}