-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathuploadBintray.gradle
executable file
·162 lines (149 loc) · 5.35 KB
/
uploadBintray.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
// bintray插件
apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish'
// 包的GroupId
def pkgGroupId = BINTRAY_PKG_GROUP_ID
// 包的ArtifactId
def pkgArtifactId = BINTRAY_PKG_ARTIFACT_ID
// 包的版本号,下次更新是只需要更改版本号即可
def pkgVersion = BINTRAY_PKG_VERSION
// 包的打包方式 aar/jar
def pkgPackaging = BINTRAY_PKG_PACKAGING
// bintray上的仓库名
def pkgRepo = BINTRAY_PKG_REPO
// 组织名 不填默认为用户
def pkgUserOrg = BINTRA_PKG_USER_ORG
// 发布到JCenter上的项目名字
def pkgName = BINTRAY_PKG_NAME
// 项目主页
def pkgWebsiteUrl = BINTRAY_PKG_WEBSITE_URL
// 项目的版本控制地址(git/svn等)
def pkgVcsUrl = BINTRAY_PKG_VCSURL
// 项目描述
def pkgDesc = BINTRAY_PKG_DESC
// 开发者Id
def pkgDeveloperId = BINTRAY_PKG_DEVELOPER_ID
// 开发者名字
def pkgDeveloperName = BINTRAY_PKG_DEVELOPER_NAME
// 开发者邮箱
def pkgDeveloperEmail = BINTRAY_PKG_DEVELOPER_EMAIL
group = pkgGroupId
// VCS Tag
version = pkgVersion
// 生成源文件
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
// Create the pom configuration:
def pomConfig = {
licenses {
license {
// 开源协议
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
// 开发者的个人信息
id pkgDeveloperId
name pkgDeveloperName
email pkgDeveloperEmail
}
}
scm {
connection pkgVcsUrl
developerConnection pkgVcsUrl
url pkgWebsiteUrl
}
}
publishing {
publications {
Production(MavenPublication) {
// 上传到JCenter所需要的源码文件
artifact sourcesJar
groupId pkgGroupId
artifactId pkgArtifactId
version pkgVersion
pom.packaging = pkgPackaging
// The publication doesn't know about our dependencies, so
// we have to manually add them to the pom
pom.withXml {
def root = asNode()
root.children().last() + pomConfig
def dependenciesNode = asNode().appendNode('dependencies')
// Iterate over the implementation dependencies (we don't want the
// test ones), adding a <dependency> node for each
configurations.implementation.allDependencies.each {
// Ensure dependencies such as fileTree are not included.
if (it.name != 'unspecified') {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
Sandbox(MavenPublication) {
// 上传到JCenter所需要的源码文件
artifact sourcesJar
groupId pkgGroupId
artifactId pkgArtifactId
version pkgVersion
pom.packaging = pkgPackaging
// The publication doesn't know about our dependencies, so
// we have to manually add them to the pom
pom.withXml {
def root = asNode()
root.children().last() + pomConfig
def dependenciesNode = asNode().appendNode('dependencies')
// Iterate over the implementation dependencies (we don't want the
// test ones), adding a <dependency> node for each
configurations.implementation.allDependencies.each {
// Ensure dependencies such as fileTree are not included.
if (it.name != 'unspecified') {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
}
// 上传到JCenter
Properties properties = new Properties()
def localFile = project.rootProject.file('local.properties')
// local.properties exists
if (localFile.exists()) {
properties.load(localFile.newDataInputStream())
}
bintray {
if (properties.containsKey("BINTRAY_USER")) {
// 读取 项目根目录下local.properties 文件里面的 BINTRAY_USER
user = properties.getProperty("BINTRAY_USER")
}
if (properties.containsKey("BINTRAY_APIKEY")) {
// 读取 项目根目录下local.properties 文件里面的 BINTRAY_APIKEY
key = properties.getProperty("BINTRAY_APIKEY")
}
configurations = ['archives']
pkg {
// 这里的repo值必须要和你创建Maven仓库的时候的名字一样
repo = pkgRepo
// 组织名 不填默认为用户
userOrg = pkgUserOrg
// 发布到JCenter上的项目名字
name = pkgName
// 项目描述
desc = pkgDesc
websiteUrl = pkgWebsiteUrl
vcsUrl = pkgVcsUrl
licenses = ["Apache-2.0"]
publish = true
}
publications = ['Production', 'Sandbox']
}