-
Notifications
You must be signed in to change notification settings - Fork 13
/
publish.gradle
186 lines (161 loc) · 7.38 KB
/
publish.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
apply plugin: 'maven-publish'
apply plugin: 'signing'
afterEvaluate {
tasks.register('sourceJar', Jar) {
from android.sourceSets.main.java.srcDirs
getArchiveClassifier().set("sources")
}
tasks.register('javaDoc', Javadoc) {
failOnError false
def mainSrc = "$project.projectDir/src/main/java"
source = files([mainSrc])
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
// classpath += configurations.runtimeClasspath
options {
addStringOption('Xdoclint:none', '')
addStringOption('charset', 'UTF-8')
}
}
tasks.register('javadocJar', Jar) {
dependsOn javaDoc
getArchiveClassifier().set('javadoc')
from javaDoc.destinationDir
}
}
/**
* Retrieves property `ossrhPassword` stored in the gradle.properties file (in project or gradle user-root folder)
* @return
*/
def getOSSRHRepositoryPassword() {
return hasProperty('ossrhPassword') ? ossrhPassword : System.getenv("OSSRH_PASSWORD") != null ? System.getenv("OSSRH_PASSWORD") : ""
}
/**
* Retrieves property `ossrhUsername` stored in the gradle.properties file (in project or gradle user-root folder)
* @return
*/
def getOSSRHRepositoryUsername() {
return hasProperty('ossrhUsername') ? ossrhUsername : System.getenv("OSSRH_USERNAME") != null ? System.getenv("OSSRH_USERNAME") : ""
}
def getGithubPublishUsername() {
return hasProperty('githubUsername') ? githubUsername : System.getenv("GITHUB_USERNAME") != null ? System.getenv("GITHUB_USERNAME") : ""
}
def getGithubPackagesAccessToken() {
return hasProperty('githubAccessToken') ? githubAccessToken : System.getenv("GITHUB_ACCESS_TOKEN") != null ? System.getenv("GITHUB_ACCESS_TOKEN") : ""
}
static def getDate() {
return new Date().format('yyyy-MM-dd HH:mm:ss')
}
/**
* Run ./gradlew :utils:clean && ./gradlew :utils:assembleRelease && ./gradlew :utils:publish
* Run ./gradlew :library:clean && ./gradlew :library:assembleRelease && ./gradlew :library:publish
* This publishes to all production artefact repositories
*/
afterEvaluate {
publishing {
publications {
mavenJava(MavenPublication) {
artifactId project.name
artifact(layout.buildDirectory.file("outputs/aar/$artifactId-release.aar"))
artifact(sourceJar)
artifact(javadocJar)
groupId 'io.ona.kujaku'
version this.version
//The publication doesn't know about our dependencies, so we have to manually add them to the pom
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
//Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
configurations.implementation.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
pom {
if (project.name == "utils") {
name = 'Kujaku Utils'
description = 'Utilities for Mapping and check-in library for Android using MapBox SDK'
} else if (project.name == "library") {
name = 'Kujaku Library'
description = 'Mapping and check-in library for Android using MapBox SDK'
}
url = 'http://github.com/onaio/kujaku'
packaging = 'aar'
licenses {
license {
name = 'BSD 2-Clause "Simplified" License'
url = 'https://raw.githubusercontent.com/onaio/kujaku/master/LICENSE'
}
}
developers {
developer {
id = 'opensrp'
name = 'OpenSRP Dev'
}
developer {
id = 'onaio'
name = 'Onaio'
}
}
scm {
connection = 'scm:git:git://github.com/onaio/kujaku.git'
developerConnection = 'scm:git:ssh://github.com/onaio/kujaku.git'
url = 'http://github.com/onaio/kujaku'
}
}
}
}
repositories {
maven {
name = "GitHubPackages"
/** Configure path of your package repository on Github
* Replace GITHUB_USERID with your or organisation Github userID and REPOSITORY with the repository name on GitHub
* e.g. "https://maven.pkg.github.com/opensrp/opensrp-client-reporting"
*/
url = uri("https://maven.pkg.github.com/onaio/kujaku")
credentials {
/** Create github.properties in root project folder file with
* gpr.usr=GITHUB_USER_ID & gpr.key=PERSONAL_ACCESS_TOKEN
* Or set env variable GPR_USER & GPR_API_KEY if not adding a properties file
*/
username = getGithubPublishUsername()
password = getGithubPackagesAccessToken()
}
}
maven {
name = "MavenCentral"
/** Configure path of your package repository on Github
* Replace GITHUB_USERID with your or organisation Github userID and REPOSITORY with the repository name on GitHub
* e.g. "https://maven.pkg.github.com/opensrp/opensrp-client-reporting"
*/
def repositoryURL
def timestampMsg = " at " + getDate()
if (!version.contains("SNAPSHOT")) {
println 'PROCESSING MAVEN RELEASE BUILD VERSION ' + project.VERSION_NAME + timestampMsg + '...'
repositoryURL = hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
: "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
} else {
println 'PROCESSING MAVEN REMOTE SNAPSHOT BUILD VERSION ' + project.VERSION_NAME + timestampMsg + '...'
repositoryURL = hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
: "https://s01.oss.sonatype.org/content/repositories/snapshots/"
}
url = uri(repositoryURL)
credentials {
/** Create gradle.properties in root project folder file with
* ossrhUsername=GITHUB_USER_ID & ossrhPassword=PERSONAL_ACCESS_TOKEN
*/
username = getOSSRHRepositoryUsername()
password = getOSSRHRepositoryPassword()
}
}
}
}
signing {
required !version.contains("SNAPSHOT")
sign(publishing.publications['mavenJava'])
}
artifacts {
archives sourceJar
archives javadocJar
}
}