-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.gradle
217 lines (175 loc) · 5.85 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
// Add to classpath dependencies for building the script
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-docker-plugin:2.6.5'
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
classpath 'org.asciidoctor:asciidoctorj-screenshot:0.1.0'
}
}
plugins {
id 'net.nemerosa.versioning' version '1.5.0'
id "de.undercouch.download" version "2.1.0"
}
apply plugin: 'war'
apply plugin: 'pmd'
apply plugin: 'maven-publish'
// all projects need JaCoCo integration, compiling in Java 8 and similar group and version strategy
allprojects {
sourceCompatibility = 1.8
targetCompatibility = 1.8
group = 'org.starwars'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
}
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.7.5.201505241946"
}
// there are dependencies that are common on core project (this) and all other subprojects like testing libraries
dependencies {
providedCompile 'javax:javaee-api:7.0'
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-library:1.3'
testCompile 'org.apache.cxf:cxf-rt-rs-client:3.1.4'
testCompile 'org.apache.johnzon:johnzon-jaxrs:0.9.2-incubating'
testCompile 'com.github.tomakehurst:wiremock:2.0.8-beta'
testCompile('org.mockito:mockito-all:1.10.19') {
exclude group: 'org.hamcrest'
}
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
// aggregates jacoco results from all subprojects and core project and generate a report
task jacocoRootTestReport(type: JacocoReport) {
sourceSets sourceSets.main
def jacocoTestFiles = ["$buildDir/jacoco/test.exec"]
subprojects.each { p ->
def coverageFileLocation = "$p.buildDir/jacoco/test.exec"
if (new File(coverageFileLocation).exists()) {
jacocoTestFiles << coverageFileLocation
}
}
logger.info('Aggregating next JaCoCo Coverage Files: {}', jacocoTestFiles)
executionData files(jacocoTestFiles)
reports {
xml.enabled false
csv.enabled false
}
}
// add pmd static code analysis
pmd {
ignoreFailures = true
ruleSets = [
"basic"
]
}
// initialize ext.config object with configuration parameters
apply from: "$rootDir/gradle/configuring.gradle"
// change version of all projects to version + (jenkinsBuild?)
allprojects {
apply from: "$rootDir/gradle/versioning.gradle"
ext.config = rootProject.ext.parsedConfig
apply from: "$rootDir/gradle/dockercompose.gradle"
}
// TODO https://plugins.gradle.org/plugin/com.github.ksoichiro.build.info
// adds a build-info file inside war file
task createBuildInfoFile << {
def buildInfoFile = new File("$buildDir/build-info.properties")
Properties props = new Properties()
props.setProperty('version', project.version.toString())
props.setProperty('timestamp', project.buildTimestamp)
props.setProperty('git_commit', versioning.info.build)
props.store(buildInfoFile.newWriter(), null)
}
// creates war with Manifest and build file information
war {
dependsOn createBuildInfoFile
from(buildDir) {
include 'build-info.properties'
into('WEB-INF/classes')
}
manifest {
attributes "Implementation-Version": project.version.toString()
}
}
// creates Docker image for developers
// IMPORTANT: this task is not intend to be used by Jenkins
// Now to work with Docker-Machine
apply plugin: 'com.bmuschko.docker-remote-api'
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
docker {
if (System.env.containsKey('DOCKER_HOST') && System.env.containsKey('DOCKER_CERT_PATH')) {
url = System.env.DOCKER_HOST.replace("tcp", "https")
certPath = new File(System.env.DOCKER_CERT_PATH)
}
}
task buildImage(type: DockerBuildImage) {
dependsOn assemble
inputDir = project.rootDir
tag = "${config.common.docker.organization}/${config.common.docker.image}:latest"
}
buildImage.onlyIf {project.hasProperty('env') && project.getProperty('env') == 'dev'}
// to publish artifact (war) we need to create sourceJar (jar with sources) and javadocJar (jar with javadoc) tasks
// so those are called and attached to the publish
task sourceJar(type: Jar) {
from sourceSets.main.allJava
}
task javadocJar (type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
}
// gets from config variable the location where artifacts are published
ext.repoUrl = "$config.binaryRepository.url/$config.binaryRepository.name"
// publish artifact to
publishing {
publications {
webApp(MavenPublication){
from components.web
// sourceJar task created previously
artifact sourceJar {
classifier "sources"
}
// javadocJar task created previously
artifact javadocJar {
classifier "javadoc"
}
}
}
// Local directory is used for simplification
repositories {
maven {
url repoUrl
}
}
}
apply plugin: 'org.asciidoctor.gradle.asciidoctor'
asciidoctor {
sourceDir = file('src/asciidoc')
attributes = [
'screenshot-dir-name': "../screens",
'rootdir': "${rootDir}"
]
}
task downloadFile(type: de.undercouch.gradle.tasks.download.Download) {
src 'https://github.com/sdaschner/jaxrs-analyzer/releases/download/v0.9/jaxrs-analyzer.jar'
dest buildDir
}
task runJaxRsAnalyzer(type:Exec) {
if (!new File("${buildDir}/jaxrs-analyzer.jar").exists()) {
dependsOn downloadFile
}
workingDir "${buildDir}"
def args = [
"-b",
"asciidoc",
"-o",
"${buildDir}/starwarsendpoints.adoc",
"${buildDir}/classes/main"
]
commandLine "java -jar ${buildDir}/jaxrs-analyzer.jar -b asciidoc -o ${buildDir}/starwarsendpoints.adoc ${buildDir}/classes/main"
}