-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
rp-publish.gradle
166 lines (131 loc) · 4.58 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
// 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)
def mUser = getPropertyExt('RP_MAVEN_USER')
def mPwd = getPropertyExt('RP_MAVEN_PWD')
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 pbArtifactId = ${pbArtifactId}"
+ "\n mUser = ${mUser}"
+ "\n mPwd = ${mPwd}"
+ "\n pbBintayKey = ${pbBintayKey}"
)
//// task
if (isAndroid()) { // Android libraries
task androidSourcesJar(type: Jar) {
archiveClassifier.set('sources')
from android.sourceSets.main.java.srcDirs
}
task androidJavadocs(type: Javadoc) {
failOnError = false
source = android.sourceSets.main.java.srcDirs
ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath += files(ext.androidJar)
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
archiveClassifier.set('javadoc')
from androidJavadocs.destinationDir
}
} else { // Java libraries
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar, javadocJar
}
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
apply plugin: 'maven-publish'
final def theGroup = group // group will be reset to 'upload'
publishing {
repositories {
maven {
url = uri('file://${System.getenv('HOME')}/.m2/repository')
if (mUser && mPwd) {
credentials {
username = mUser
password = mPwd
}
}
}
}
publications {
mavenJava(MavenPublication) {
groupId = theGroup
version = version
artifactId = pbArtifactId
if (pbArtifactId.endsWith('gradle')) {
from components.java
} else {
// 必须有这个 否则不会上传AAR包
afterEvaluate {
artifact(androidSourcesJar)
artifact(androidJavadocsJar)
artifact(tasks.getByName("bundleReleaseAar"))
}
}
}
}
}