1- apply plugin : ' maven'
1+ apply plugin : ' maven-publish '
22apply plugin : ' signing'
33
4- afterEvaluate { project ->
5- uploadArchives {
6- repositories {
7- mavenDeployer {
8- beforeDeployment { MavenDeployment deployment -> signing. signPom(deployment) }
9- pom. groupId = GROUP
10- pom. artifactId = POM_ARTIFACT_ID
11- pom. version = VERSION_NAME
12- repository(url : " https://oss.sonatype.org/service/local/staging/deploy/maven2/" ) {
13- authentication(userName : getRepositoryUsername(), password : getRepositoryPassword())
14- }
15- pom. project {
16- name POM_NAME
17- packaging POM_PACKAGING
18- description POM_DESCRIPTION
19- url POM_URL
20- scm {
21- url POM_SCM_URL
22- connection POM_SCM_CONNECTION
23- developerConnection POM_SCM_DEV_CONNECTION
24- }
25- licenses {
26- license {
27- name POM_LICENCE_NAME
28- url POM_LICENCE_URL
29- distribution POM_LICENCE_DIST
30- }
31- }
32- developers {
33- developer {
34- id POM_DEVELOPER_ID
35- name POM_DEVELOPER_NAME
4+ def isReleaseBuild () {
5+ return ! VERSION_NAME . contains(" SNAPSHOT" )
6+ }
7+
8+ def getReleaseRepositoryUrl () {
9+ return hasProperty(' RELEASE_REPOSITORY_URL' ) ? RELEASE_REPOSITORY_URL
10+ : " https://oss.sonatype.org/service/local/staging/deploy/maven2/"
11+ }
12+
13+ def getSnapshotRepositoryUrl () {
14+ return hasProperty(' SNAPSHOT_REPOSITORY_URL' ) ? SNAPSHOT_REPOSITORY_URL
15+ : " https://oss.sonatype.org/content/repositories/snapshots/"
16+ }
17+
18+ task androidJavadocs (type : Javadoc ) {
19+ exclude " **/*.orig" // exclude files created by source control
20+ source = android. sourceSets. main. java. srcDirs
21+ classpath + = project. files(android. getBootClasspath(). join(File . pathSeparator))
22+ failOnError false
23+ }
24+
25+ task androidJavadocsJar (type : Jar , dependsOn : androidJavadocs) {
26+ archiveClassifier. set(" javadoc" )
27+
28+ from androidJavadocs. destinationDir
29+ }
30+
31+ task androidSourcesJar (type : Jar ) {
32+ archiveClassifier. set(" sources" )
33+
34+ from android. sourceSets. main. java. source
35+ }
36+
37+ def logger (log ) {
38+ println log
39+ }
40+
41+ def configurePom (pom ) {
42+ logger(" configurePom" )
43+ pom. name = POM_NAME
44+ pom. packaging = POM_PACKAGING
45+ pom. description = POM_DESCRIPTION
46+ pom. url = POM_URL
47+
48+ pom. scm {
49+ url = POM_SCM_URL
50+ connection = POM_SCM_CONNECTION
51+ developerConnection = POM_SCM_DEV_CONNECTION
52+ }
53+
54+ pom. licenses {
55+ license {
56+ name = POM_LICENCE_NAME
57+ url = POM_LICENCE_URL
58+ distribution = POM_LICENCE_DIST
59+ }
60+ }
61+
62+ pom. developers {
63+ developer {
64+ id = POM_DEVELOPER_ID
65+ name = POM_DEVELOPER_NAME
66+ }
67+ }
68+ }
69+
70+ afterEvaluate {
71+ publishing {
72+ publications {
73+ release(MavenPublication ) {
74+ logger(" release" )
75+ // The coordinates of the library, being set from variables that
76+ // we'll set up in a moment
77+ groupId GROUP
78+ artifactId POM_ARTIFACT_ID
79+ version VERSION_NAME
80+
81+ // Two artifacts, the `aar` and the sources
82+ // artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
83+ artifact bundleReleaseAar
84+ artifact androidSourcesJar
85+ artifact androidJavadocsJar
86+
87+ // Self-explanatory metadata for the most part
88+ pom {
89+ configurePom(pom)
90+ // A slight fix so that the generated POM will include any transitive dependencies
91+ // that the library builds upon
92+ withXml {
93+ def dependenciesNode = asNode(). appendNode(' dependencies' )
94+
95+ project. configurations. implementation. allDependencies. each {
96+ def dependencyNode = dependenciesNode. appendNode(' dependency' )
97+ dependencyNode. appendNode(' groupId' , it. group)
98+ dependencyNode. appendNode(' artifactId' , it. name)
99+ dependencyNode. appendNode(' version' , it. version)
36100 }
37101 }
38102 }
39103 }
40104 }
41- }
42- signing {
43- required { gradle. taskGraph. hasTask(" uploadArchives" ) }
44- sign configurations. archives
45- }
46- task androidJavadocs(type : Javadoc ) {
47- classpath + = project. files(android. getBootClasspath(). join(File . pathSeparator))
48- if (JavaVersion . current(). isJava8Compatible()) {
49- allprojects {
50- tasks. withType(Javadoc ) { options. addStringOption(' Xdoclint:none' , ' -quiet' ) }
105+ repositories {
106+ maven {
107+ name = " sonatype"
108+
109+ // You only need this if you want to publish snapshots, otherwise just set the URL
110+ // to the release repo directly
111+ url = isReleaseBuild() ? getReleaseRepositoryUrl() : getSnapshotRepositoryUrl()
112+
113+ credentials(PasswordCredentials ) {
114+ username = getRepositoryUsername()
115+ password = getRepositoryPassword()
116+ }
51117 }
52118 }
53119 }
54- task androidJavadocsJar( type : Jar , dependsOn : androidJavadocs) {
55- archiveClassifier = ' javadoc '
56- from androidJavadocs . destinationDir
57- }
58- task androidSourcesJar( type : Jar ) {
59- classifier = ' sources '
60- from android . sourceSets . main . java . sourceFiles
61- }
62- artifacts { archives androidJavadocsJar }
63- }
120+ }
121+
122+ signing {
123+ logger( " signing " )
124+ sign publishing . publications
125+ }
126+
127+
128+ publish . dependsOn build
129+ publishToMavenLocal . dependsOn build
0 commit comments