forked from Qihoo360/RePlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rp-publish.gradle
200 lines (155 loc) · 5.03 KB
/
rp-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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// utilities
def static replaceVariables(File file, String key, String value) {
if(!file.exists()) return
def regex = '\\$\\{' + key + '\\}'
file.write((file.text =~ /${regex}/).replaceAll(value))
}
def isAndroid(){ return project.hasProperty("android"); }
def getPropertySafe(name, defaultValue = ''){
if(hasProperty(name) && getProperty(name).trim() != '') return getProperty(name)
return defaultValue
}
def getPropertyExt(name, defaultValue = ''){
if ( project.ext.has(name) && project.ext[name] != null ) return project.ext[name]
return getPropertySafe(name, defaultValue)
}
// def pbHelp(){
// println(">>> Please make sure MUST-HVAE Properties defined in 'project.ext' or gradle.properties."
// + "\ne.g.: "
// + "\n PB_USER = hyongbai"
// + "\n PB_ARTIFACT_ID = HelloWorld"
// )
// }
def pbUpdateVariables(){
[
"src/main/groovy/com/qihoo360/replugin/gradle/host/AppConstant.groovy",
"src/main/groovy/com/qihoo360/replugin/gradle/plugin/AppConstant.groovy"
].forEach { replaceVariables(project.file(it), "RP_VERSION", version) }
}
// pbHelp()
///// CONFIG
apply from: "${buildscript.sourceFile.parent}/rp-config.gradle"
group = getPropertyExt('RP_GROUP')
version = getPropertyExt('RP_VERSION')
def pbArtifactId = getPropertyExt('RP_ARTIFACT_ID')
pbUpdateVariables()
//
def pbUser = getPropertyExt('RP_USER')
def pbRepo = getPropertyExt('RP_REPO', 'maven')
def pbEmail = getPropertyExt('RP_EMAIL', pbUser)
def pbUserId = getPropertyExt('RP_USER_ID', pbUser)
def pbUserOrg = getPropertyExt('RP_USERORG', '')
def pbBintayKey = getPropertyExt('RP_BINTRAY_KEY', System.getenv('RP_BINTRAY_KEY'))
//
def pbDesc = getPropertyExt('RP_DESC', 'DONT BE EVIL')
def pbLicense = getPropertyExt('RP_LICENSES_NAME', 'The Apache Software License, Version 2.0')
def pbLicenseUrl = getPropertyExt('RP_LICENSES_URL', 'http://www.apache.org/licenses/LICENSE-2.0.txt')
//
def pbSiteUrl = getPropertyExt('RP_SITE', "https://github.com")
def pbGitUrl = getPropertyExt('RP_GIT_URL', pbSiteUrl)
def pbIssueUrl = getPropertyExt('RP_ISSUE_URL', pbSiteUrl)
println(
">>>「publish.gradle」 CONFIGURATIONS:"
+ "\n ${group}:${pbArtifactId}:${version}"
+ "\n ${pbDesc}"
+ "\n Android = ${project.hasProperty("android")}"
+ "\n pbUser = ${pbUser}:${pbEmail}"
+ "\n pbSite = ${pbSiteUrl}"
+ "\n pbGitUrl = ${pbGitUrl}"
+ "\n pbIssueUrl = ${pbIssueUrl}"
+ "\n License = ${pbLicense}(${pbLicenseUrl})"
+ "\n pbBintayKey = ${pbBintayKey}"
)
//// task
if (isAndroid()) { // Android libraries
task sourcesJar(overwrite: true, type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
task javadoc(overwrite: true, type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
} else { // Java libraries
task sourcesJar(overwrite: true, type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
}
task javadocJar(overwrite: true, type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
// archives javadocJar
archives sourcesJar
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
// TODO: mavenLocal & jcenter conflicts
if ( pbBintayKey == null ){
System.err.println("\n>>>「publish.gradle」bintray access key is EMPTY, UPLOAD LOCAL ONLY!\n")
///// publish to LOCAL
apply plugin: 'maven'
final def theGroup = group // group will be reset to 'upload'
uploadArchives {
repositories.mavenDeployer {
repository(url: "file://${System.getenv('HOME')}/.m2/repository")
pom.groupId = theGroup
pom.version = version
pom.artifactId = pbArtifactId
}
}
return
}
/////// publish to BINTRAY
apply plugin: 'com.jfrog.bintray'
if (isAndroid()) {
apply plugin: 'com.github.dcendents.android-maven'
}
install {
repositories.mavenInstaller {
pom {
project {
packaging 'aar'
name pbArtifactId
url pbSiteUrl
licenses {
license {
name pbLicense
url pbLicenseUrl
}
}
developers {
developer {
id pbUser
name pbUserId
email pbEmail
}
}
scm {
connection pbGitUrl
developerConnection pbGitUrl
url pbSiteUrl
}
}
}
}
}
bintray {
user = pbUser
key = pbBintayKey
configurations = ['archives']
pkg {
desc = pbDesc
repo = pbRepo
name = pbArtifactId
vcsUrl = pbGitUrl
userOrg = pbUserOrg
websiteUrl = pbSiteUrl
issueTrackerUrl = pbIssueUrl
licenses = [pbLicense]
publish = true
}
}