-
Notifications
You must be signed in to change notification settings - Fork 16
/
build.gradle
325 lines (294 loc) · 11.3 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
import org.apache.tools.ant.filters.ReplaceTokens
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
plugins {
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'com.github.kt3k.coveralls' version '2.12.2'
id 'com.marklogic.ml-gradle' version '4.6.0'
id 'io.github.ddimtirov.codacy' version '0.1.0'
id 'org.sonarqube' version '4.0.0.2929'
id 'eclipse'
id 'idea'
id 'jacoco'
id 'java'
id 'java-library'
id 'maven-publish'
id 'signing'
}
ext {
// we don't need a REST server, only an XCC server
mlAppDeployer.getCommands().remove(mlAppDeployer.getCommand('DeployRestApiServersCommand'))
mlAppConfig {
name = project.name
customTokens.put('%%XDBC_PORT%%', '8223')
createTriggersDatabase = false
}
}
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
repositories {
mavenCentral()
flatDir {
dirs 'src/test/resources/'
}
}
sourceSets {
test {
// adding main resources from build dir, in order to load HTML with tokens replaced
resources.srcDir sourceSets.main.output.resourcesDir
}
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/test/java')
}
resources.srcDir file('src/test/resources')
}
performanceTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/test/java')
}
resources.srcDir file('src/test/resources')
}
}
configurations {
shadow {
extendsFrom api //will ensure that XCC is listed as a dependency
}
integrationTestImplementation.extendsFrom testImplementation
integrationTestRuntimeOnly.extendsFrom testRuntimeOnly
performanceTestImplementation.extendsFrom testImplementation
performanceTestRuntimeOnly.extendsFrom testRuntimeOnly
// encountered issues publishing since upgrading to Gradle 6:
/* What went wrong:
Execution failed for task ':publishMainJavaPublicationToMavenLocal'.
> Failed to publish publication 'mainJava' to repository 'mavenLocal'
> Artifact marklogic-corb-2.5.1.jar wasn't produced by this build.
*/
// Suggested workaround: https://docs.gradle.org/current/userguide/upgrading_version_6.html#publishing_spring_boot_applications
[apiElements, runtimeElements].each {
it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }
}
}
dependencies {
api 'com.marklogic:marklogic-xcc:11.1.0'
// JavaScript libraries are bundled in a fat jar for the UI
implementation "org.webjars:angularjs:$angularVersion"
shadow "org.webjars:angularjs:$angularVersion"
implementation "org.webjars:bootstrap:$bootstrapVersion"
shadow "org.webjars:bootstrap:$bootstrapVersion"
implementation "org.webjars:jquery:$jqueryVersion"
shadow "org.webjars:jquery:$jqueryVersion"
// externalsortinginjava classes with the corb distro in a fat jar
implementation "com.google.code.externalsortinginjava:externalsortinginjava:$externalsortinginjavaVersion"
shadow "com.google.code.externalsortinginjava:externalsortinginjava:$externalsortinginjavaVersion"
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
testImplementation 'org.jasypt:jasypt:1.9.3'
testImplementation 'com.github.stefanbirkner:system-rules:1.19.0' //facilitates tests for methods that invoke System.exit
testImplementation 'org.mockito:mockito-all:1.10.19'
}
test {
//we will run Integration and Performance tests in separate tasks
exclude '**/*IT.class'
exclude '**/*PT.class'
}
// perform token replacement in HTML for JavaScript library version paths
processResources {
with copySpec {
duplicatesStrategy = 'include'
from ('src/main/resources/web') {
include '*.html'
}
into ('web')
filter(ReplaceTokens, tokens: [ANGULAR_VERSION: angularVersion, BOOTSTRAP_VERSION: bootstrapVersion, JQUERY_VERSION: jqueryVersion])
}
}
processTestResources.dependsOn processResources
//disabling, because we want to incorporate externalsortingjava and UI resources in uber jar and use as the artifact
jar {
enabled = false
dependsOn(shadowJar { classifier = null })
}
shadowJar {
//project.configurations.implementation.canBeResolved = true
configurations = [project.configurations.shadow]
dependencies {
include(dependency("com.google.code.externalsortinginjava:externalsortinginjava:$externalsortinginjavaVersion"))
include(dependency('org.webjars:.*'))
}
//generate same name as the jar task would
//archiveFileName = "${archiveBaseName}-${archiveVersion}.${archiveExtension}"
archiveFileName = "${baseName}-${version}.${extension}"
manifest {
attributes 'Application-Version': project.version
attributes 'Build-date' : new Date()
attributes 'Main-Class' : 'com.marklogic.developer.corb.Manager'
attributes 'Name': 'com/marklogic/developer/corb/'
attributes 'Specification-Title' : 'corb'
attributes 'Specification-Version' : project.version
attributes 'Implementation-Title' : project.name
//Manager class reads the version for usage messages
attributes 'Implementation-Version' : project.version
}
}
sonarqube {
properties {
property "sonar.projectKey", "corb2"
property "sonar.organization", "marklogic-community"
property "sonar.host.url", "https://sonarcloud.io"
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
description = "Create a JAR of source files; required for publishing"
classifier 'sources'
from sourceSets.main.allJava
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from 'build/docs/javadoc'
}
jacocoTestReport {
reports {
xml.required = true // coveralls plugin depends on xml format report
html.required = true
}
}
task integrationTest(type: Test, dependsOn: test) {
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
filter {
//include all integration tests
includeTestsMatching "*IT"
}
//If you want to ensure that integration tests are run every time when you invoke
//this task, uncomment the following line.
//outputs.upToDateWhen { false }
jacoco {
destinationFile = file("$buildDir/jacoco/test.exec")
}
//generate the Jacoco report
finalizedBy { tasks.integrationTestReport }
}
task integrationTestReport(type: JacocoReport) {
sourceSets sourceSets.main
executionData integrationTest
}
task performanceTest(type: Test) {
testClassesDirs = sourceSets.performanceTest.output.classesDirs
classpath = sourceSets.performanceTest.runtimeClasspath
filter {
//include all performance tests
includeTestsMatching "*PT"
}
//If you want to ensure that performance tests are run every time when you invoke
//this task, uncomment the following line.
outputs.upToDateWhen { false }
}
check.dependsOn jacocoTestReport
//Ensure that the check task fails the build if there are failing integration tests.
check.dependsOn integrationTest
//Ensure that our unit tests are run before our integration tests
integrationTest.mustRunAfter test
integrationTest.onlyIf { !project.hasProperty('skipIntegrationTest') }
//Ensure that the check task fails the build if there are failing performance tests.
//check.dependsOn performanceTest
//Ensure that our unit tests are run before our performance tests
performanceTest.mustRunAfter integrationTest
performanceTest.onlyIf { !project.hasProperty('skipPerformanceTest') }
tasks.withType(Test) {
reports.html.destination = file("${reporting.baseDir}/${name}")
testLogging {
// set options for log level LIFECYCLE
events TestLogEvent.FAILED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_OUT
showExceptions true
exceptionFormat TestExceptionFormat.SHORT
showCauses true
showStackTraces true
// set options for log level DEBUG and INFO
debug {
events TestLogEvent.FAILED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_OUT,
TestLogEvent.STANDARD_ERROR
exceptionFormat TestExceptionFormat.FULL
}
info.events = debug.events
info.exceptionFormat = debug.exceptionFormat
afterSuite { desc, result ->
if (!desc.parent) { // will match the outermost suite
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
def startItem = '| ', endItem = ' |'
def repeatLength = startItem.length() + output.length() + endItem.length()
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
}
}
}
}
tasks.coveralls {
dependsOn 'check'
}
// Having both runtimeElements and shadowRuntimeElements variants makes it harder to resolve CoRB as a dependency and is confusing.
// We just want the fat jar listed and seen as the only option.
components.java.withVariantsFromConfiguration(configurations.getByName("runtimeElements")) {
skip()
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
pom.withXml {
asNode().children().last() + {
resolveStrategy = Closure.DELEGATE_FIRST
name "corb"
url project.websiteUrl
scm {
url project.vcsUrl
}
issueManagement {
system "GitHub Issues"
url project.issueTrackerUrl
}
licenses {
license {
name "The Apache Software License, Version 2.0"
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
distribution "repo"
}
}
description 'CoRB is a Java tool designed for bulk content-reprocessing of documents stored in MarkLogic.'
developers {
developer {
name "Bhagat Bandlamudi"
email "[email protected]"
organization "MarkLogic"
}
developer {
name "Mads Hansen"
email "[email protected]"
organization "MarkLogic"
}
}
}
}
}
}
repositories {
maven {
url ossURL
credentials {
username ossUsername
password ossPassword
}
}
}
}
signing {
sign publishing.publications.mavenJava
}