forked from strongloop-community/loopback-sdk-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
266 lines (223 loc) · 8.07 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
group = 'com.strongloop';
logger.info('**JVM VERSION** ' + org.gradle.internal.jvm.Jvm.current())
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.1'
classpath 'org.apache.commons:commons-io:1.3.2'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
}
}
apply plugin: 'com.android.library'
apply plugin: 'android-maven'
apply plugin: 'signing'
import org.apache.commons.io.FilenameUtils;
def sonatypeRepositoryUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
def isJenkinsBuild = System.getenv("BUILD_NUMBER")
def isReleaseBuild = !version.contains("SNAPSHOT")
def shouldPublishToMavenCentral = isReleaseBuild
repositories {
mavenLocal()
mavenCentral()
maven {
url "http://artifactory.strongloop.com:8081/artifactory/repo/"
}
}
android {
compileSdkVersion 21
buildToolsVersion "21.0.2"
defaultConfig {
minSdkVersion 8
targetSdkVersion 20
}
}
dependencies {
compile 'org.atteo:evo-inflector:1.2'
compile 'com.google.guava:guava:17.0'
compile 'com.loopj.android:android-async-http:1.4.5'
}
task unpackJavadocIncludes(type: Sync) {
// unpack all source dependencies
into 'build/javadoc-sources'
}
android.libraryVariants.all { variant ->
def name = variant.buildType.name
if (name.equals('DEBUG')) {
return; // Skip debug builds.
}
// define androidReleaseJar task
task("android${name.capitalize()}Jar", type: Jar) {
dependsOn variant.javaCompile
from variant.javaCompile.destinationDir
}
// define androidReleaseJavadoc task
task("generate${name.capitalize()}Javadoc", type: Javadoc) {
description "Generates Javadoc for $variant.name."
dependsOn unpackJavadocIncludes
source variant.javaCompile.source
source fileTree('build/javadoc-sources').matching {
include '**/*.java'
}
ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
logger.info('**JAVADOC CLASSPATH for ' + name + '**')
classpath.each {
logger.info ' ' + it.absolutePath
if (!it.isFile() && !it.isDirectory()) {
logger.error('INVALID CLASSPATH ITEM ' + it.absolutePath);
}
}
verbose = logger.isEnabled(LogLevel.INFO)
}
}
afterEvaluate { project ->
task updateApiDocs(type: Sync, dependsOn: generateReleaseJavadoc) {
from generateReleaseJavadoc.destinationDir
into 'docs/api'
}
task androidJavadocsJar(type: Jar, dependsOn: generateReleaseJavadoc) {
classifier = 'javadoc'
from generateReleaseJavadoc.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
// Tasks for building dist.zip
task distProperties() { doLast {
new File(androidReleaseJar.archivePath.absolutePath + '.properties').withWriter { w ->
w.println('src=src/' + androidSourcesJar.archiveName)
w.println('doc=docs/' + androidJavadocsJar.archiveName)
}
// hack: create properties file for strong-remoting-android
configurations.compile.resolve().each { dep ->
if (dep.name.startsWith('strong-remoting-android')) {
new File(dep.absolutePath + '.properties').withWriter { w ->
def baseName = FilenameUtils.getBaseName(dep.absolutePath)
w.println('src=src/' + baseName + '-sources.jar')
w.println('doc=docs/' + baseName + '-javadoc.jar')
}
}
}
} }
// Structure based on
// http://stackoverflow.com/questions/9873152/how-to-attach-javadoc-or-sources-to-jars-in-libs-folder
task dist(type: Zip, dependsOn: [
androidReleaseJar,
androidJavadocsJar,
androidSourcesJar,
distProperties]) {
classifier 'eclipse-bundle'
def root = project.name + '-' + project.version;
into(root + '/libs') {
from(androidReleaseJar.archivePath)
from(androidReleaseJar.archivePath.absolutePath + '.properties')
}
// bundle in dependencies
configurations.compile.resolve().each { dep ->
// exclude jars from Android SDK
if (dep.absolutePath.contains('/com/android/')) return
into(root + '/libs') {
from (dep.absolutePath)
// include -sources and -docs for strong-remoting-android
if (dep.name.startsWith('strong-remoting-android')) {
def baseName = FilenameUtils.getBaseName(dep.absolutePath)
from(dep.absolutePath + '.properties')
}
}
}
into(root + '/libs/docs') {
from(androidJavadocsJar.archivePath)
}
into(root + '/libs/src') {
from(androidSourcesJar.archivePath)
}
into(root) {
from('docs/README.dist') {
rename 'README.dist', 'README'
}
}
}
artifacts {
archives androidReleaseJar
archives androidSourcesJar
archives androidJavadocsJar
archives dist
}
// Maven publishing
uploadArchives {
repositories {
mavenDeployer {
if (shouldPublishToMavenCentral) {
beforeDeployment { MavenDeployment deployment ->
signing.signPom(deployment)
}
repository(url: sonatypeRepositoryUrl) {
authentication(
userName: sonatypeUserName,
password: sonatypePassword);
}
}
pom.project {
name 'loopback-sdk-android'
description 'Android client for LoopBack'
url 'https://github.com/strongloop/loopback-sdk-android'
licenses {
license {
name 'The MIT License'
url 'http://opensource.org/licenses/mit-license.php'
distribution 'repo'
}
}
scm {
connection 'scm:[email protected]:strongloop/loopback-sdk-android.git'
developerConnection 'scm:[email protected]:strongloop/loopback-sdk-android.git'
url 'https://github.com/strongloop/loopback-sdk-android'
}
developers {
developer {
id 'bajtos'
name 'Miroslav Bajtos'
email '[email protected]'
organization = 'StrongLoop, Inc.'
organizationUrl 'http://strongloop.com/'
}
}
}
pom.withXml {
def root = asNode()
root.appendNode('packaging', 'jar');
}
}
}
}
// Task for Jenkins build that will conditionally
// call uploadArchives, but only if there is something
// to upload
task publishToMavenCentral {
if (shouldPublishToMavenCentral)
dependsOn uploadArchives
}
if (shouldPublishToMavenCentral) {
signing {
required {
gradle.taskGraph.hasTask("uploadArchives")
}
sign configurations.archives
}
}
// debugging
task printCompilerInput << {
logger.info "**JAVAC INPUT FILES**"
compileReleaseJava.source.each {
logger.info ' ' + it.absolutePath
}
logger.info "**JAVAC CLASSPATH**"
compileReleaseJava.classpath.each {
logger.info ' ' + it.absolutePath
}
}
compileReleaseJava.dependsOn printCompilerInput
}