-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
230 lines (196 loc) · 6.2 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
import org.gradle.testing.jacoco.tasks.JacocoCoverageVerification
import java.text.SimpleDateFormat
buildscript {
repositories {
mavenCentral()
maven {
name 'Gradle Plugins'
url 'https://plugins.gradle.org/m2/'
}
maven {
name 'Spring Plugins'
url 'https://repo.spring.io/plugins-release'
}
}
dependencies {
classpath 'org.ajoberstar:gradle-git:1.7.1'
}
}
plugins {
id 'java'
id 'checkstyle'
id 'pmd'
id 'findbugs'
id 'jacoco'
id 'com.diffplug.gradle.spotless' version '3.8.0'
id 'com.gorylenko.gradle-git-properties' version '1.4.20'
}
repositories {
mavenCentral()
}
description = 'Java wrapper for the Hetzner Cloud API'
version = '0.1-SNAPSHOT'
buildDir = 'target'
sourceCompatibility = 1.8
ext {
slf4jVersion = '1.7.25'
lombokVersion = '1.16.20'
springVersion = '5.0.3.RELEASE'
commonsLangVersion = '3.7'
jacksonDatatypeJsr310Version = '2.9.3'
logbackVersion = '1.2.3'
junitVersion = '4.12'
mockitoVersion = '1.10.19'
assertjVersion = '3.9.0'
jsonassertVersion = '1.5.0'
checkstyleVersion = '8.7'
pmdVersion= '5.5.2'
findbugsVersion = '3.0.1'
jacocoVersion = '0.7.9'
buildDate = new SimpleDateFormat("dd.MM.yyyy HH:mm").format(new Date())
gitRepositoryUrl = 'https://github.com/riy/hcloud-java.git'
configDir = "${project.projectDir}/etc/config"
}
sourceSets {
generated
main {
compileClasspath += generated.output
runtimeClasspath += generated.output
}
test {
compileClasspath += generated.output
runtimeClasspath += generated.output
}
}
dependencies {
compile "org.slf4j:slf4j-api:${slf4jVersion}"
compileOnly "org.projectlombok:lombok:${lombokVersion}"
compile "org.springframework:spring-web:${springVersion}"
compile "org.apache.commons:commons-lang3:${commonsLangVersion}"
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${jacksonDatatypeJsr310Version}"
compile "ch.qos.logback:logback-core:${logbackVersion}"
compile "ch.qos.logback:logback-classic:${logbackVersion}"
testCompile "junit:junit:${junitVersion}"
testCompile "org.mockito:mockito-core:${mockitoVersion}"
testCompile "ch.qos.logback:logback-core:${logbackVersion}"
testCompile "ch.qos.logback:logback-classic:${logbackVersion}"
testCompile "org.assertj:assertj-core:${assertjVersion}"
testCompile "org.skyscreamer:jsonassert:${jsonassertVersion}"
testCompile "org.projectlombok:lombok:${lombokVersion}"
checkstyle "com.puppycrawl.tools:checkstyle:${checkstyleVersion}"
}
clean {
delete file('coverage')
delete file('reports')
}
task failIfGitNotClean {
doLast {
def grgit = org.ajoberstar.grgit.Grgit.open(project.file('.'))
def status = grgit.status()
if (!status.isClean()) {
throw new GradleException('There are some un-committed files in this project.\nStaged changes: ' + status.staged.allChanges + '.\nUnstaged changes: ' + status.unstaged.allChanges)
}
}
}
tasks.withType(JavaCompile) {
options.encoding = "ISO-8859-1"
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
gitProperties {
gitPropertiesDir = sourceSets.generated.resources.sourceDirectories.singleFile
}
processGeneratedResources.dependsOn generateGitProperties
jar {
baseName = 'hcloud-java'
from sourceSets.generated.output
}
checkstyle {
sourceSets = [sourceSets.main, sourceSets.test]
configFile = file("${project.configDir}/checkstyle/checkstyle.xml")
configProperties = ['suppressionFile': "${project.configDir}/checkstyle/suppressions.xml"]
ignoreFailures = false
}
// fail on checkstyle warnings, see https://github.com/gradle/gradle/issues/881
tasks.withType(Checkstyle).each { checkstyleTask ->
checkstyleTask.doLast {
reports.all { report ->
def outputFile = report.destination
if (outputFile.exists() && outputFile.text.contains("<error ")) {
throw new GradleException("There were checkstyle warnings! For more info check $outputFile")
}
}
}
}
pmd {
toolVersion = pmdVersion
sourceSets = [sourceSets.main, sourceSets.test]
ruleSets = []
ruleSetFiles = files("${project.configDir}/pmd/ruleset.xml")
rulePriority = 4
}
findbugs {
toolVersion = findbugsVersion // manually uploaded to K+N Enterprise Repository
sourceSets = [sourceSets.main, sourceSets.test]
effort = 'default'
reportLevel = 'high'
}
tasks.withType(FindBugs) {
reports {
xml.enabled false
html.enabled true
}
}
tasks.withType(Test).each { test ->
test.logging.captureStandardOutput LogLevel.INFO
test.testLogging {
showStandardStreams = false // Set 'true' to see more output during tests
exceptionFormat "full"
}
}
jacoco {
toolVersion = jacocoVersion
}
jacocoTestReport {
reports {
xml.enabled true
html.enabled true
}
afterEvaluate {
classDirectories = files(classDirectories.files).asFileTree.matching {
exclude '**/*$CoverageProblem*'
}
}
doFirst {
if (!gradle.taskGraph.hasTask(test)) {
throw new StopExecutionException()
}
}
}
jacocoTestReport.dependsOn test
test.finalizedBy jacocoTestReport
def relativeJacocoCoverageReportDir = '/reports/jacoco/test'
// TODO REMOVE def jacocoCoverageReportDir = "${buildDir}${relativeJacocoCoverageReportDir}"
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.1 // Will be increased over time
}
}
}
}
check.dependsOn jacocoTestCoverageVerification
task coverage {
dependsOn test, jacocoTestCoverageVerification
}
spotless {
// automatically format source files, see https://github.com/diffplug/spotless
java {
importOrderFile rootProject.file("${project.configDir}/ide/hcloud-java.importorder")
eclipse().configFile rootProject.file("${project.configDir}/ide/eclipse_formatter.xml")
target 'src/main/**/*.java', 'src/test/**/*.java'
}
}
test {
systemProperty 'token', System.getProperty('token')
}