1616 * source: https://github.com/chrisbanes/gradle-mvn-push
1717 */
1818
19- apply plugin : ' maven'
19+ apply plugin : ' maven-publish '
2020apply plugin : ' signing'
2121
22+ version = VERSION_NAME
23+ group = GROUP
24+
2225def isReleaseBuild () {
2326 return VERSION_NAME . contains(" SNAPSHOT" ) == false
2427}
@@ -41,85 +44,136 @@ def getRepositoryPassword() {
4144 return hasProperty(' NEXUS_PASSWORD' ) ? NEXUS_PASSWORD : " "
4245}
4346
47+ def configurePom (pom ) {
48+ pom. name = POM_NAME
49+ pom. packaging = POM_PACKAGING
50+ pom. description = POM_DESCRIPTION
51+ pom. url = POM_URL
52+
53+ pom. scm {
54+ url = POM_SCM_URL
55+ connection = POM_SCM_CONNECTION
56+ developerConnection = POM_SCM_DEV_CONNECTION
57+ }
58+
59+ pom. licenses {
60+ license {
61+ name = POM_LICENCE_NAME
62+ url = POM_LICENCE_URL
63+ distribution = POM_LICENCE_DIST
64+ }
65+ }
66+
67+ pom. developers {
68+ developer {
69+ id = POM_DEVELOPER_ID
70+ name = POM_DEVELOPER_NAME
71+ }
72+ developer {
73+ id = POM_DEVELOPER_ID2
74+ name = POM_DEVELOPER_NAME2
75+ }
76+ developer {
77+ id = POM_DEVELOPER_ID3
78+ name = POM_DEVELOPER_NAME3
79+ }
80+ }
81+ }
82+
4483afterEvaluate { project ->
45- uploadArchives {
84+ publishing {
85+ publications {
86+ release(MavenPublication ) {
87+ groupId GROUP
88+ artifactId POM_ARTIFACT_ID
89+ version VERSION_NAME
90+ from components. release
91+ }
92+ }
93+
4694 repositories {
47- mavenDeployer {
48- beforeDeployment { MavenDeployment deployment -> signing. signPom(deployment) }
95+ maven {
96+ def releasesRepoUrl = getReleaseRepositoryUrl()
97+ def snapshotsRepoUrl = getSnapshotRepositoryUrl()
98+ url = isReleaseBuild() ? releasesRepoUrl : snapshotsRepoUrl
99+
100+ credentials(PasswordCredentials ) {
101+ username = getRepositoryUsername()
102+ password = getRepositoryPassword()
103+ }
104+ }
105+ }
106+ }
49107
50- pom. groupId = GROUP
51- pom. artifactId = POM_ARTIFACT_ID
52- pom. version = VERSION_NAME
108+ if (project. getPlugins(). hasPlugin(' com.android.application' ) ||
109+ project. getPlugins(). hasPlugin(' com.android.library' )) {
53110
54- repository(url : getReleaseRepositoryUrl()) {
55- authentication(userName : getRepositoryUsername(), password : getRepositoryPassword())
56- }
57- snapshotRepository(url : getSnapshotRepositoryUrl()) {
58- authentication(userName : getRepositoryUsername(), password : getRepositoryPassword())
59- }
111+ task androidJavadocs(type : Javadoc ) {
112+ source = android. sourceSets. main. java. source
113+ classpath + = project. files(android. getBootClasspath(). join(File . pathSeparator))
114+ excludes = [' **/*.kt' ]
115+ }
60116
61- pom. project {
62- name POM_NAME
63- packaging POM_PACKAGING
64- description POM_DESCRIPTION
65- url POM_URL
66-
67- scm {
68- url POM_SCM_URL
69- connection POM_SCM_CONNECTION
70- developerConnection POM_SCM_DEV_CONNECTION
71- }
72-
73- licenses {
74- license {
75- name POM_LICENCE_NAME
76- url POM_LICENCE_URL
77- distribution POM_LICENCE_DIST
78- }
79- }
80-
81- developers {
82- developer {
83- id POM_DEVELOPER_ID
84- name POM_DEVELOPER_NAME
85- }
86- developer {
87- id POM_DEVELOPER_ID2
88- name POM_DEVELOPER_NAME2
89- }
90- developer {
91- id POM_DEVELOPER_ID3
92- name POM_DEVELOPER_NAME3
93- }
94- }
95- }
117+ task androidJavadocsJar(type : Jar , dependsOn : androidJavadocs) {
118+ classifier = ' javadoc'
119+ from androidJavadocs. destinationDir
120+ }
121+
122+ task androidSourcesJar(type : Jar ) {
123+ classifier = ' sources'
124+ from android. sourceSets. main. java. source
125+ }
126+ }
127+
128+ if (JavaVersion . current(). isJava8Compatible()) {
129+ allprojects {
130+ tasks. withType(Javadoc ) {
131+ options. addStringOption(' Xdoclint:none' , ' -quiet' )
96132 }
97133 }
98134 }
99135
100- signing {
101- required { isReleaseBuild() && gradle. taskGraph. hasTask(" uploadArchives" ) }
102- def signingKey = findProperty(" signingKey" )
103- def signingPassword = findProperty(" signingPassword" )
104- useInMemoryPgpKeys(signingKey, signingPassword)
105- sign configurations. archives
136+ if (JavaVersion . current(). isJava9Compatible()) {
137+ allprojects {
138+ tasks. withType(Javadoc ) {
139+ options. addBooleanOption(' html5' , true )
140+ }
141+ }
142+ }
143+
144+ artifacts {
145+ if (project. getPlugins(). hasPlugin(' com.android.application' ) ||
146+ project. getPlugins(). hasPlugin(' com.android.library' )) {
147+ archives androidSourcesJar
148+ archives androidJavadocsJar
149+ }
150+ }
151+
152+ android. libraryVariants. all { variant ->
153+ tasks. androidJavadocs. doFirst {
154+ classpath + = files(variant. javaCompileProvider. get(). classpath. files. join(File . pathSeparator))
155+ }
106156 }
107157
108- // task androidJavadocs(type: Javadoc) {
109- // source = android.sourceSets.main.allJava
110- // }
158+ publishing . publications . all { publication ->
159+ publication . groupId = GROUP
160+ publication . version = VERSION_NAME
111161
112- // task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
113- // classifier = 'javadoc'
114- // from androidJavadocs.destinationDir
115- // }
162+ publication. artifact androidSourcesJar
163+ publication. artifact androidJavadocsJar
116164
117- task androidSourcesJar(type : Jar ) {
118- classifier = ' sources'
119- from android. sourceSets. main. java. sourceFiles
165+ configurePom(publication. pom)
120166 }
121167
122- artifacts {
123- archives androidSourcesJar
168+ signing {
169+ if (findProperty(" signingKey" )) {
170+ def signingKey = findProperty(" signingKey" )
171+ def signingPassword = findProperty(" signingPassword" )
172+ useInMemoryPgpKeys(signingKey, signingPassword)
173+ }
174+
175+ publishing. publications. all { publication ->
176+ sign publication
177+ }
124178 }
125179}
0 commit comments