forked from mercedes-benz/sechub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-java.gradle
121 lines (97 loc) · 3.37 KB
/
build-java.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
// SPDX-License-Identifier: MIT
/* ============================================================================
This file contains the configurations for
Java settings
============================================================================
Included from: "${rootProject.projectDir}/build.gradle"
============================================================================
*/
if (JavaVersion.current().isJava8Compatible()) {
allprojects {
tasks.withType(Javadoc) {
// turn off doclint
options.addStringOption('Xdoclint:none', '-quiet')
enabled = false
}
}
}
ext.buildContainsFailedTests=false
subprojects{
if (! projectType.javaProjects.contains(project)){
return;
}
apply plugin: 'java'
/* Setup UTF-8 for compile AND test compilation*/
[ compileJava, compileTestJava ]*.options*.encoding = 'UTF-8'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
def wireMockHttpPortValue = 8180;
def wireMockHttpsPortValue = 8143;
/* Per default GRADLE stops the build if one single test fails. We want to have all tests executed. */
test {
ignoreFailures = true
def wireMockHttpPortProperty="sechub.test.wiremock.http_port";
if ( project.hasProperty(wireMockHttpPortProperty)){
wireMockHttpPortValue = project.getProperty(wireMockHttpPortProperty)
}
def wireMockHttpsPortProperty="sechub.test.wiremock.https_port";
if ( project.hasProperty(wireMockHttpsPortProperty)){
wireMockHttpsPortValue = project.getProperty(wireMockHttpsPortProperty)
}
environment 'SECHUB_TEST_WIREMOCK_HTTP_PORT', "$wireMockHttpPortValue"
environment 'SECHUB_TEST_WIREMOCK_HTTPS_PORT', "$wireMockHttpsPortValue"
environment 'SECHUB_BUILD_GRADLE', 'true' // we can use this to check for gradle build inside java tests
// add a collection to track failedTests
ext.failedTests = []
// add a testlistener to all tasks of type Test
tasks.withType(Test) {
afterTest { TestDescriptor descriptor, TestResult result ->
if(result.resultType == org.gradle.api.tasks.testing.TestResult.ResultType.FAILURE){
buildContainsFailedTests=true
failedTests << ["${descriptor.className}::${descriptor.name}"]
}
}
}
// print out tracked failed tests when the build has finished
gradle.buildFinished {
if(!failedTests.empty){
println "Failed tests for ${project.name}:"
failedTests.each { failedTest ->
println failedTest
}
println ""
}
}
}
/**
* Task to create source jars
*/
task sourcesJar(type: Jar, dependsOn:classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
/**
* Task to create javadoc jars
*/
task javadocJar(type: Jar, dependsOn:javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
/**
* Define artifacts
*/
artifacts {
archives sourcesJar
archives javadocJar
}
}
allprojects {
if(! project.name.equals(rootProject.name) ) {
return
}
gradle.buildFinished {
if (buildContainsFailedTests){
throw new GradleException('Some tests have failed!')
}
}
}