This repository has been archived by the owner on Mar 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
/
build.gradle
205 lines (182 loc) · 7.56 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
/*
* Copyright © 2016, 2018 IBM Corp. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
plugins {
id "com.github.spotbugs" version "2.0.0" apply false
}
subprojects {
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'signing'
group = 'com.cloudant'
version = new File(rootDir, 'VERSION').text.trim()
// Note the gradle subproject names (e.g. cloudant-client, cloudant-http) are the maven
// artifactIds - the maven pom project name entry and User-Agent name in com.cloudant.client.properties are
// defined by this clientName.
ext.clientName = 'java-cloudant'
// If the version says "snapshot" anywhere assume it is not a release
ext.isReleaseVersion = !version.toUpperCase(Locale.ENGLISH).contains("SNAPSHOT")
sourceCompatibility = 1.6
targetCompatibility = 1.6
repositories {
mavenLocal()
mavenCentral()
}
// Include variable debug info in the compiled classes
compileJava.options.debugOptions.debugLevel = "source,lines,vars"
// Fail on javac warnings
compileJava.options.compilerArgs << "-Werror"
// Suppress the bootstrap class path warning which will always apply if we build on a JVM newer
// than the -source setting and do not set the
// "-bootclasspath pathToJREMatchingSourceLevel/jre/lib/rt.jar"
compileJava.options.compilerArgs << "-Xlint:-options"
// Always UTF-8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
tasks.withType(Test) {
// Pick up properties named test.* from command line, gradle.properties first
System.properties.each { prop ->
if (prop.key.startsWith("test")) {
systemProperty prop.key, prop.value
}
}
// This property cannot be set dynamically on OpenJDK so set it here
// to allow SSL tunnelling through HTTP proxy for testing
systemProperties.put("jdk.http.auth.tunneling.disabledSchemes", "")
testLogging {
// Get full exceptions for test failures
exceptionFormat = 'full'
// Log all tests, not just failures. Include test output.
events "passed", "skipped", "failed", "standardOut", "standardError"
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
sourceSets.all {
into(name + "/java", { from allJava })
into(name + "/resources", { from resources })
}
}
javadoc {
options.encoding 'UTF-8'
options.setMemberLevel JavadocMemberLevel.PROTECTED
// Add a logging listener to check for javadoc warnings and fail the build if there are any
boolean hasJavaDocWarnings = false;
doFirst {
getLogging().addStandardErrorListener(new StandardOutputListener() {
void onOutput(CharSequence output) {
if (output =~ "warning:") {
hasJavaDocWarnings = true
}
}
})
}
doLast {
if (hasJavaDocWarnings) {
throw new GradleException("Build failed due to javadoc warnings.");
}
}
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar, javadocJar
}
// Load signing and repository parameters from system properties
['signing.keyId', 'signing.password', 'signing.secretKeyRingFile', 'ossrhUsername', 'ossrhPassword']
.each { propName ->
//set a property with the given name if the system property is set
//if the system property is not set then set the property to null if it isn't a signing one
if (System.properties.(propName.toString()) != null || !propName.startsWith("signing")) {
ext.(propName.toString()) = System.properties.(propName.toString())
}
}
signing {
// Only apply signing when it is a release and is being published
required {
isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives")
}
// When signing, sign the archives
sign configurations.archives
}
uploadArchives {
repositories {
mavenDeployer {
// When publishing sign the pom
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
// Augment the pom with additional information
pom.project {
name project.clientName
packaging 'jar'
url 'https://cloudant.com'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
scm {
connection 'scm:git:git://github.com/cloudant/java-cloudant.git'
developerConnection 'scm:git:git@github.com/cloudant/java-cloudant.git'
url 'https://java-cloudant@github.com/cloudant/java-cloudant.git'
}
properties {
'project.build.sourceEncoding' 'UTF-8'
}
developers {
developer {
name 'IBM Cloudant'
email 'support@cloudant.com'
url 'https://cloudant.com'
organization 'IBM'
organizationUrl 'http://www.ibm.com'
}
}
}
}
}
}
// Findbugs
apply plugin: 'com.github.spotbugs'
spotbugs {
toolVersion = "3.1.12"
// Report only high severity bugs for now
reportLevel = "low"
// The code base is pretty small so use max effort
effort = "max"
// We don't want to run findbugs on the test code yet
sourceSets = [sourceSets.main]
// Exclude a couple of known bugs until we get the chance to fix them
if (file("spotbugs_excludes.xml").exists()) {
excludeFilter = file("spotbugs_excludes.xml")
}
}
tasks.withType(com.github.spotbugs.SpotBugsTask) {
// Currently only one report type can be used toggle which with a property
boolean generateXML = Boolean.getBoolean("spotbugs.xml.report")
reports {
xml.enabled = generateXML
html.enabled = !generateXML
}
}
}