forked from cloudant/java-cloudant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
212 lines (183 loc) · 6.77 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
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'signing'
group = 'com.cloudant'
version = '1.1.2'
description = """java-cloudant"""
//note the gradle project name (cloudant-client) is the maven artifactId
//the maven pom name entry and User-Agent name in client.properties are defined by 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()
}
dependencies {
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.3'
compile group: 'com.google.code.gson', name: 'gson', version: '2.2.4'
testCompile group: 'junit', name: 'junit', version: '4.8.2'
}
//include variable debug info in the compiled classes
compileJava.options.debugOptions.debugLevel = "source,lines,vars"
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
}
}
}
test {
// Run tests for any DB
useJUnit {
excludeCategories 'com.cloudant.test.main.RequiresCloudant',
'com.cloudant.test.main.RequiresCouch'
}
}
task noDBTest(type: Test, dependsOn: testClasses) {
// Run tests that can use any Cloudant
useJUnit {
excludeCategories 'com.cloudant.test.main.RequiresDB'
}
}
task cloudantTest(type: Test, dependsOn: testClasses) {
// Run tests that can use any Cloudant
useJUnit {
excludeCategories 'com.cloudant.test.main.RequiresCloudantService'
}
}
task cloudantServiceTest(type: Test, dependsOn: testClasses) {
// Run all Cloudant service tests
useJUnit {
excludeCategories 'com.cloudant.test.main.RequiresCloudantLocal',
'com.cloudant.test.main.RequiresCouch'
}
}
//task for generating a client properties file
class ClientProperties extends DefaultTask {
//allow this to be configured, default to client.properties
File clientPropsPath = new File("client.properties")
//internal
private Properties p = new Properties()
def load() {
//if there is a generated file already load the values
if (clientPropsPath.exists()) {
p.load(new FileInputStream(clientPropsPath));
}
}
@TaskAction
def save() {
p.put("user.agent.name", project.clientName)
p.put("user.agent.version", project.version)
p.store(new FileOutputStream(clientPropsPath), "User agent information for this client")
}
String getPropertyValue(String key) {
return p.getProperty(key)
}
}
//generate a client props file, make the jar task depend on this
task generateClientPropertiesFile(type: ClientProperties) {
clientPropsPath = new File(buildDir, "tmp/client.properties")
outputs.upToDateWhen {
if (clientPropsPath.exists()) {
it.load()
return project.clientName.equals(it.getPropertyValue("user.agent.name")) && project.version.equals(it.getPropertyValue("user.agent.version"))
} else {
return false
}
}
}
jar.dependsOn generateClientPropertiesFile
//include the client props in the built jar
jar {
into "META-INF", { from generateClientPropertiesFile.clientPropsPath }
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
sourceSets.all {
into(name + "/java", { from allJava })
into(name + "/resources", { from resources })
}
}
javadoc {
exclude("**/com/cloudant/tests/**",
"**/com/cloudant/test/**",
"**/resources/**")
include("**/lightcouch/DocumentConflictException.java",
"**/lightcouch/NoDocumentException.java",
"**/lightcouch/CouchDbException.java",
"**/client/**")
}
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 {
packaging 'jar'
name project.clientName
description 'Official Cloudant client for Java'
inceptionYear '2014'
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:[email protected]/cloudant/java-cloudant.git'
url 'https://[email protected]/cloudant/java-cloudant.git'
}
properties {
'project.build.sourceEncoding' 'UTF-8'
}
developers {
developer {
name 'IBM Cloudant'
email '[email protected]'
url 'https://cloudant.com'
organization 'IBM'
organizationUrl 'http://www.ibm.com'
}
}
}
}
}
}