-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease-bintray.gradle
More file actions
200 lines (165 loc) · 6.88 KB
/
release-bintray.gradle
File metadata and controls
200 lines (165 loc) · 6.88 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
apply plugin: 'com.android.library'
// Upload to Maven-Central
apply plugin: 'maven-publish'
apply plugin: 'signing'
//配置from local.properties
ext["signing.keyId"] = ''
ext["signing.password"] = ''
ext["signing.secretKeyRingFile"] = ''
ext["ossrhUsername"] = ''
ext["ossrhPassword"] = '' //
//TODO: end
//配置from project gradle
version = VERSION_NAME
//配置from gradle.properties
group = GROUP
File secretPropsFile = project.rootProject.file('local.properties')
if (secretPropsFile.exists()) {
println "Found secret props file, loading props"
Properties p = new Properties()
p.load(new FileInputStream(secretPropsFile))
p.each { name, value ->
ext[name] = value
}
} else {
println "No props file, loading env vars"
}
// Android tasks for Javadoc and sources.jar generation
afterEvaluate { project ->
task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
exclude '**/pom.xml'
exclude '**/proguard_annotations.pro'
classpath += files(android.bootClasspath)
}
task androidJavadocsJar(type: Jar) {
archiveClassifier = 'javadoc'
from androidJavadoc.destinationDir
}
task androidSourcesJar(type: Jar) {
archiveClassifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
android.libraryVariants.all { variant ->
def name = variant.name.capitalize()
task "jar${name}"(type: Jar, dependsOn: variant.javaCompile) {
from variant.javaCompile.destinationDir
}
}
artifacts.add('archives', androidJavadocsJar)
artifacts.add('archives', androidSourcesJar)
}
// JIRA: https://issues.sonatype.org/browse/OSSRH-65440?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel
// Sonatype: https://s01.oss.sonatype.org/
def getReleaseRepositoryUrl() {
return hasProperty('LOCAL') ? localMavenRepo()
: hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
: 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/'
}
def getSnapshotRepositoryUrl() {
return hasProperty('LOCAL') ? localMavenRepo()
: hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
: 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
}
publishing {
publications {
release(MavenPublication) {
// The coordinates of the library, being set from variables that
// we'll set up in a moment
groupId GROUP
artifactId POM_ARTIFACT_ID
version VERSION_NAME
// Two artifacts, the `aar` and the sources
afterEvaluate {
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
artifact androidSourcesJar
// Self-explanatory metadata for the most part
pom {
name = POM_NAME
description = POM_DESCRIPTION
// If your project has a dedicated site, use its URL here
url = POM_URL
licenses {
license {
//协议类型,一般默认Apache License2.0的话不用改:
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution = 'repo'
}
}
developers {
developer {
id = POM_DEVELOPER_ID
name = POM_DEVELOPER_NAME
email = POM_DEVELOPER_EMAIL
}
}
// Version control info, if you're using GitHub, follow the format as seen here
scm {
//修改成你的Git地址:
connection = POM_SCM_URL
developerConnection = POM_SCM_CONNECTION
//分支地址:
url = POM_SCM_DEV_CONNECTION
}
// A slightly hacky fix so that your POM will include any transitive dependencies
// that your library builds upon
//添加依赖需要afterEvaluate
withXml {
def dependenciesNode = asNode().appendNode('dependencies')
project.configurations.implementation.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
print("添加依赖库:"+it.group + ":" + it.name + ":"+ it.version)
}
}
}
}
}
}
repositories {
// The repository to publish to, Sonatype/MavenCentral
maven {
// This is an arbitrary name, you may also use "mavencentral" or
// any other name that's descriptive for you
name = "MavenCentral"
def releasesRepoUrl = getReleaseRepositoryUrl()
//"https://oss.sonatype.org/service/local/staging/deploy/maven2/"
def snapshotsRepoUrl = getSnapshotRepositoryUrl()
//"https://oss.sonatype.org/content/repositories/snapshots/"
// You only need this if you want to publish snapshots, otherwise just set the URL
// to the release repo directly
url = version.contains('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
// The username and password we've fetched earlier
// def ossrhUsername = getRepositoryUsername()
// def ossrhPassword = getRepositoryPassword()
print("ossrhUsername=" + ossrhUsername + " $VERSION_NAME" + " 没想到子仓库的的子moudle会调用子仓库的gradle。子仓库的属性变量也能加载 " + url)
credentials {
username ossrhUsername
password ossrhPassword
}
}
}
}
afterEvaluate {
signing {
sign publishing.publications
}
}
afterEvaluate {
Task build = project.tasks.getByName("build")
Task assemble = project.tasks.getByName("assemble")
Task signReleasePublication = project.tasks.getByName("signReleasePublication")
Task bundleReleaseAar = project.tasks.getByName("bundleReleaseAar")
signReleasePublication.dependsOn(bundleReleaseAar)
project.tasks.findAll {
it.name.startsWith("publish")
}.each {
it.dependsOn(build)
it.dependsOn(assemble)
it.dependsOn(signReleasePublication)
it.dependsOn(bundleReleaseAar)
}
}