Skip to content

Commit 2642541

Browse files
committed
feat: 增加 maven发布脚本
1 parent 9a4acb9 commit 2642541

4 files changed

Lines changed: 181 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
.externalNativeBuild
1515
.cxx
1616
local.properties
17+
maven-secret.properties

maven.properties

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
GROUP_ID=io.github.feer921
2+
ARTIFACT_ID=AndroidStartup
3+
VERSION_NAME=1.0
4+
5+
#POM_PACKAGING=jar
6+
7+
CUSTOM_ARTIFACT=./build/outputs/aar/AndroidStartup-release.aar
8+
POM_PACKAGING=aar
9+
10+
11+
12+
POM_NAME=AndroidStartup
13+
POM_URL=https://github.com/feer921/AndroidStartup
14+
POM_DESCRIPTION=Common help app startup faster library
15+
POM_INCEPTION_YEAR=2023
16+
17+
POM_SCM_URL=https://github.com/feer921/AndroidStartup
18+
POM_SCM_CONNECTION=scm:git@https://github.com/feer921/AndroidStartup.git
19+
POM_SCM_DEV_CONNECTION=scm:git@https://github.com/feer921/AndroidStartup.git
20+
21+
POM_LICENCE_COMMENTS=A business-friendly OSS license
22+
POM_LICENCE_NAME=The Apache Software License, Version 2.0
23+
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
24+
POM_LICENCE_DIST=repo
25+
26+
POM_DEVELOPER_ID=feer921
27+
POM_DEVELOPER_NAME=feer921
28+
POM_DEVELOPER_EMAIL=feer921@163.com
29+
POM_DEVELOPER_URL=https://github.com/feer921/AndroidStartup
30+
POM_ISSUE_MANAGEMENT_SYSTEM=Github
31+
POM_ISSUE_MANAGEMENT_URL=https://github.com/feer921/AndroidStartup

theAndroidStartup/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
id 'com.android.library'
33
id 'org.jetbrains.kotlin.android'
44
}
5+
apply from:'maven_publish.gradle' //依赖 maven 发布脚本
56

67
android {
78
compileSdk 31
@@ -27,6 +28,11 @@ android {
2728
kotlinOptions {
2829
jvmTarget = '11'
2930
}
31+
publishing {
32+
singleVariant('release') {
33+
withSourcesJar()
34+
}
35+
}
3036
}
3137

3238
dependencies {
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
apply plugin: 'maven-publish'
2+
apply plugin: 'signing'
3+
//apply plugin: 'java'
4+
5+
6+
//java {
7+
// withJavadocJar()
8+
// withSourcesJar()
9+
//}
10+
11+
//加载配置参数
12+
Properties p = new Properties()
13+
p.load(project.rootProject.file('maven.properties').newDataInputStream())
14+
//项目 GAV 信息
15+
def GROUP_ID = getProperty(p, 'GROUP_ID')
16+
def ARTIFACT_ID = getProperty(p, 'ARTIFACT_ID')
17+
def VERSION_NAME = getProperty(p, 'VERSION_NAME')
18+
// POM信息
19+
def POM_NAME = getProperty(p, 'POM_NAME')
20+
def POM_URL = getProperty(p, 'POM_URL')
21+
def POM_DESCRIPTION = getProperty(p, 'POM_DESCRIPTION')
22+
def POM_INCEPTION_YEAR = getProperty(p, 'POM_INCEPTION_YEAR')
23+
def POM_SCM_URL = getProperty(p, 'POM_SCM_URL')
24+
def POM_SCM_CONNECTION = getProperty(p, 'POM_SCM_CONNECTION')
25+
def POM_SCM_DEV_CONNECTION = getProperty(p, 'POM_SCM_DEV_CONNECTION')
26+
// 开源许可
27+
def POM_LICENCE_COMMENTS = getProperty(p, 'POM_LICENCE_COMMENTS')
28+
def POM_LICENCE_NAME = getProperty(p, 'POM_LICENCE_NAME')
29+
def POM_LICENCE_URL = getProperty(p, 'POM_LICENCE_URL')
30+
def POM_LICENCE_DIST = getProperty(p, 'POM_LICENCE_DIST')
31+
32+
//开发者信息
33+
def POM_DEVELOPER_ID = getProperty(p, 'POM_DEVELOPER_ID')
34+
def POM_DEVELOPER_NAME = getProperty(p, 'POM_DEVELOPER_NAME')
35+
def POM_DEVELOPER_EMAIL = getProperty(p, 'POM_DEVELOPER_EMAIL')
36+
def POM_DEVELOPER_URL = getProperty(p, 'POM_DEVELOPER_URL')
37+
//issue 信息
38+
def POM_ISSUE_MANAGEMENT_SYSTEM = getProperty(p, 'POM_ISSUE_MANAGEMENT_SYSTEM')
39+
def POM_ISSUE_MANAGEMENT_URL = getProperty(p, 'POM_ISSUE_MANAGEMENT_URL')
40+
//MAVEN账密私密信息
41+
Properties p4Secret = new Properties()
42+
p4Secret.load(rootProject.file('maven-secret.properties').newDataInputStream())
43+
44+
def MAVEN_USER_NAME = getProperty(p4Secret, 'MAVEN_USERNAME')
45+
def MAVEN_PW = getProperty(p4Secret, 'MAVEN_PASSWORD')
46+
def SIGN_KEYID = getProperty(p4Secret, 'signing.keyId')
47+
def SIGN_PW = getProperty(p4Secret, 'signing.password')
48+
def SIGN_SECRET_KEYRING_FILE = getProperty(p4Secret, 'signing.secretKeyRingFile')
49+
50+
private def getProperty(Properties p, String key) {
51+
return p.getProperty(key)
52+
}
53+
54+
//用于打包源代码的任务
55+
task androidSourcesJar(type: Jar) {
56+
archiveClassifier.set('sources')
57+
from android.sourceSets.main.java.srcDirs
58+
}
59+
60+
//afterEvaluate {
61+
publishing {
62+
publications {
63+
release(MavenPublication) {
64+
// from components.release
65+
groupId GROUP_ID //开通maven central时候定义的
66+
artifactId ARTIFACT_ID //资源名称
67+
version VERSION_NAME //版本名称
68+
project.ext['signing.keyId'] = SIGN_KEYID
69+
project.ext['signing.password'] = SIGN_PW
70+
project.ext['signing.secretKeyRingFile'] = SIGN_SECRET_KEYRING_FILE
71+
72+
pom {
73+
name = POM_NAME
74+
description = POM_DESCRIPTION
75+
url = POM_URL
76+
inceptionYear = POM_INCEPTION_YEAR
77+
78+
scm {
79+
url = POM_SCM_URL
80+
connection = POM_SCM_CONNECTION
81+
developerConnection = POM_SCM_DEV_CONNECTION
82+
}
83+
84+
licenses {
85+
license {
86+
name = POM_LICENCE_NAME
87+
url = POM_LICENCE_URL
88+
distribution = POM_LICENCE_DIST
89+
comments = POM_LICENCE_COMMENTS
90+
}
91+
}
92+
93+
developers {
94+
developer {
95+
id = POM_DEVELOPER_ID
96+
name = POM_DEVELOPER_NAME
97+
email = POM_DEVELOPER_EMAIL
98+
url = POM_DEVELOPER_URL
99+
}
100+
}
101+
102+
issueManagement {
103+
system = POM_ISSUE_MANAGEMENT_SYSTEM
104+
url = POM_ISSUE_MANAGEMENT_URL
105+
}
106+
}
107+
108+
afterEvaluate {
109+
from components.release
110+
}
111+
// artifact androidSourcesJar
112+
113+
// artifact generateSourcesJar //需要上传的source jar
114+
// artifact generateJavadoc //需要上传的java doc
115+
// artifact makeJar //需要上传的资源jar路径或者是aar路径,这边可以填写一个生成jar的task,如makeJar方法就是一个生成jar的task
116+
}
117+
}
118+
repositories {
119+
maven {
120+
// 指定要上传的maven仓库
121+
url = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/'
122+
//Maven仓库用户名和密码
123+
credentials {
124+
username MAVEN_USER_NAME
125+
password MAVEN_PW
126+
}
127+
}
128+
}
129+
}
130+
131+
//}
132+
133+
signing {
134+
sign project.publishing.publications
135+
// useInMemoryPgpKeys(SIGN_KEYID, SIGN_PW)
136+
// sign stuffZip
137+
}
138+
139+
//javadoc {
140+
// if(JavaVersion.current().isJava9Compatible()) {
141+
// options.addBooleanOption('html5', true)
142+
// }
143+
//}

0 commit comments

Comments
 (0)