This repository was archived by the owner on Jul 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
259 lines (228 loc) · 9.95 KB
/
build.gradle
File metadata and controls
259 lines (228 loc) · 9.95 KB
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
/*
* Copyright © 2016, 2017 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.
*/
subprojects {
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'signing'
group = 'com.cloudant'
version = new File(rootDir, 'VERSION').text.trim()
description = """A Java object cache for use with the java-cloudant client"""
// If the version says "snapshot" anywhere assume it is not a release
ext.isReleaseVersion = !version.toUpperCase(Locale.ENGLISH).contains("SNAPSHOT")
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
}
// Additional configurations for javadoc
configurations {
inheritableJavadoc {
transitive false
}
linkableJavadoc {
transitive false
}
}
dependencies {
// Cloudant client (java-cloudant) version
def javaCloudantVersion = '2.8.0'
// Dependency on java-cloudant
compile group: 'com.cloudant', name: 'cloudant-client', version: javaCloudantVersion
// Dependencies for inheriting javadoc and creating doc links
inheritableJavadoc group: 'com.cloudant', name: 'cloudant-client', version: javaCloudantVersion, classifier: 'sources'
linkableJavadoc group: 'com.cloudant', name: 'cloudant-client', version: javaCloudantVersion, classifier: 'javadoc'
// Test dependencies
testCompile group: 'junit', name: 'junit', version: '4.12'
}
// Include variable debug info in the compiled classes
compileJava.options.debugOptions.debugLevel = "source,lines,vars"
// Fail on javac warnings
compileJava.options.compilerArgs << "-Werror"
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
sourceSets.all {
into(name + "/java", { from allJava })
}
}
// Task to copy APIs from cloudant-client that we might want to inherit doc from
task copyInhertiedDocSource(type: Copy) {
configurations.inheritableJavadoc.forEach {
from zipTree(it)
into new File(buildDir, 'javadocInheritSources')
include 'main/java/com/cloudant/client/api/**/*.java'
}
}
gradle.projectsEvaluated {
javadoc {
// Add the client API as a sourcepath for inheriting docs, filtering/copying first
// Make sure we copy the cloudant-client doc we want to inherit
dependsOn copyInhertiedDocSource
options.addStringOption('sourcepath', new File(buildDir, 'javaDocInheritSources/main/java').absolutePath)
// For the subprojects we include all the javadoc from dependencies on other subprojects
// this produces a more standalone javadoc jar for each published artifact.
source getProjectDocSources(project).collect() { dsp ->
dsp.sourceSets.main.java
}
// Add the offline link options for the client API pointing to javadoc.io using the resolved
// java-cloudant version. Use the package-list from the javadoc zip file.
configurations.linkableJavadoc.each {
options.linksOffline('http://static.javadoc.io/com.cloudant/cloudant-client/'
+ configurations.linkableJavadoc.resolvedConfiguration.firstLevelModuleDependencies.first().moduleVersion + '/',
zipTree(it).matching {
include 'package-list'
}.singleFile.parentFile.absolutePath)
}
// Set the location of the overview.html
options.overview 'overview.html'
// Include only public members in the javadoc
options.setMemberLevel JavadocMemberLevel.PUBLIC
// 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 parameters from system properties
['signing.keyId', 'signing.password', 'signing.secretKeyRingFile']
.each { propName ->
// Set a property with the given name if the system property is set
if (System.properties.(propName.toString()) != null) {
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 {
ext.ossrhUsername = System.properties.ossrhUsername
ext.ossrhPassword = System.properties.ossrhPassword
doFirst {
// If the OSSRH credentials are not available, then fail the build
if (ossrhUsername == null || ossrhPassword == null) {
throw new GradleException('OSSRH credentials properties (ossrhUsername & ' +
'ossrhPassword) are required to upload archives.')
}
}
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 rootProject.name
packaging 'jar'
description 'Cache for java-cloudant client'
inceptionYear '2016'
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-labs/java-cloudant-cache.git'
developerConnection 'scm:git:git@github.com/cloudant-labs/java-cloudant-cache.git'
url 'https://java-cloudant-cache@github.com/cloudant-labs/java-cloudant-cache.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'
}
}
}
}
}
}
apply plugin: 'findbugs'
// Findbugs configuration
findbugs {
toolVersion = "3.0.1"
// The code base is pretty small so use max effort
effort = "max"
// Report all bugs
reportLevel = "low"
}
tasks.withType(FindBugs) {
// Currently only one report type can be used toggle which with a property
boolean generateXML = Boolean.getBoolean("findbugs.xml.report")
reports {
xml.enabled = generateXML
html.enabled = !generateXML
}
}
tasks.withType(Test) {
// Transfer all gradle System properties to the test JVM
systemProperties = System.getProperties()
// Configure test logging
testLogging {
// Get full exceptions for test failures
exceptionFormat = 'full'
// Log all tests, not just failures. Include test output.
events "passed", "skipped", "failed", "standardOut", "standardError"
}
}
}
// Function to get project doc sources (i.e. the project and all its dependent projects)
def getProjectDocSources(project) {
// Get the compile time dependencies
def projectDependencies = project.configurations.compile.getAllDependencies().withType(ProjectDependency)
// Get the projects from the dependencies
def dependentProjects = projectDependencies*.dependencyProject
// Recurse
dependentProjects.each { dependentProjects += getProjectDocSources(it) }
// Finally add the original project
//dependentProjects.add(project)
// Return without duplicates
return dependentProjects.unique()
}