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