-
Notifications
You must be signed in to change notification settings - Fork 3
/
publishing.gradle
186 lines (156 loc) · 6.75 KB
/
publishing.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'
def isCiBuild = System.getenv('ci_build') == 'true'
def artifactoryUsername = System.getenv('artifactory_username')
def artifactoryPassword = System.getenv('artifactory_password')
def artifactoryReleaseUrl = System.getenv('artifactory_release_url')
def artifactorySnapshotUrl = System.getenv('artifactory_snapshot_url')
def isSigningEnabled = isCiBuild
def isReleaseBuild = System.getenv('release_build') == 'true'
def sonatypeUsername = System.getenv('sonatype_username')
def sonatypePassword = System.getenv('sonatype_password')
println ">>>>>>>>> isCiBuild=${isCiBuild} isSigningEnabled=${isSigningEnabled} isReleaseBuild=${isReleaseBuild} <<<<<<<<<"
if (isSigningEnabled) {
signing {
project.ext["signing.keyId"] = System.getenv('signing_keyId')
project.ext["signing.password"] = System.getenv('signing_password')
project.ext["signing.secretKeyRingFile"] = "/tmp/secring.gpg"
}
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
task javadoc(type: Javadoc) {
failOnError false
source = android.sourceSets.main.java.srcDirs
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
task signSourcesJar(type: Sign, dependsOn: sourcesJar) {
sign sourcesJar
}
task signJavadocJar(type: Sign, dependsOn: javadocJar) {
sign javadocJar
}
def createSignTask(def targetFile) {
return task(type: Sign, "sign${targetFile.name.capitalize()}Output") {
sign targetFile
}
}
def createSignAarTask() {
return task(type: Sign, "signAar") {
sign bundleReleaseAar
dependsOn bundleReleaseAar
}
}
afterEvaluate {
publishing {
publications {
release(MavenPublication) {
groupId = project.group
version = project.android.defaultConfig.versionName + (isReleaseBuild ? "" : "-SNAPSHOT")
artifactId = project.artifactId
pom.packaging = 'aar'
artifact(bundleReleaseAar) {
classifier null
}
artifact javadocJar
artifact sourcesJar
generatePom(pom)
if (isSigningEnabled) {
artifact(signSourcesJar.signatureFiles.collect { it }[0]) {
extension 'jar.asc'
classifier 'sources'
builtBy signSourcesJar
}
artifact(signJavadocJar.signatureFiles.collect { it }[0]) {
extension 'jar.asc'
classifier 'javadoc'
builtBy signJavadocJar
}
def task = createSignAarTask()
artifact(signAar.signatureFiles.collect { it }[0]) {
extension 'aar.asc'
builtBy signAar
}
def pomFile = new File(buildDir, "publications/" + name + "/pom-default.xml")
task = createSignTask(pomFile)
artifact(task.signatureFiles.collect { it }[0]) {
extension 'pom.asc'
builtBy task
}
}
}
}
repositories {
//https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.repositories.MavenArtifactRepository.html
if (isCiBuild) {
maven {
name 'artifactory'
credentials {
username artifactoryUsername
password artifactoryPassword
}
url isReleaseBuild ? artifactoryReleaseUrl : artifactorySnapshotUrl
}
maven {
name = 'sonatype'
credentials {
username sonatypeUsername
password sonatypePassword
}
url isReleaseBuild ? 'https://oss.sonatype.org/service/local/staging/deploy/maven2/' :
'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
}
}
}
def generatePom(def pom) {
pom.withXml {
asNode().appendNode('name', 'Yandex Auth SDK')
asNode().appendNode('description', 'Yandex Auth SDK for Android')
asNode().appendNode('url', 'https://github.com/yandexmobile/yandex-login-sdk-android')
asNode().appendNode('developers').appendNode('developer')
.appendNode('id', 'Yandex LLC').parent()
.appendNode('name', 'Yandex LLC').parent()
.appendNode('email', 'android-dev@yandex-team.ru')
asNode().appendNode('licenses').appendNode('license')
.appendNode('name', 'Apache License, Version 2.0').parent()
.appendNode('url', 'http://www.apache.org/licenses/LICENSE-2.0.html')
asNode().appendNode('scm')
.appendNode('url', 'git@github.com:yandexmobile/yandex-login-sdk-android.git').parent()
.appendNode('connection', 'scm:git:git@github.com:yandexmobile/yandex-login-sdk-android.git').parent()
.appendNode('developerConnection', 'scm:git:git@github.com:yandexmobile/yandex-login-sdk-android.git')
def dependenciesNode = asNode().appendNode('dependencies')
// List all compile dependencies and write to POM
(configurations.implementation.getAllDependencies()
+ configurations.api.getAllDependencies()
).each { Dependency dep ->
if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified")
return // ignore invalid dependencies
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dep.group)
dependencyNode.appendNode('artifactId', dep.name)
dependencyNode.appendNode('version', dep.version)
dependencyNode.appendNode('scope', 'compile')
if (!dep.transitive) {
// If this dependency is transitive, we should force exclude all its dependencies them from the POM
def exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
exclusionNode.appendNode('groupId', '*')
exclusionNode.appendNode('artifactId', '*')
} else if (!dep.properties.excludeRules.empty) {
// Otherwise add specified exclude rules
def exclusionsNode = dependencyNode.appendNode('exclusions')
dep.properties.excludeRules.each { ExcludeRule rule ->
def exclusionNode = exclusionsNode.appendNode('exclusion')
exclusionNode.appendNode('groupId', rule.group ?: '*')
exclusionNode.appendNode('artifactId', rule.module ?: '*')
}
}
}
}
}