1+
2+ File ossrhProp = project. rootProject. file(' ossrh.properties' )
3+ if (ossrhProp. exists()) {
4+ apply plugin : ' maven-publish'
5+ apply plugin : ' signing'
6+
7+ Properties p = new Properties ()
8+ p. load(new FileInputStream (ossrhProp))
9+ p. each { name , value ->
10+ ext[name] = value
11+ }
12+
13+ task androidSourcesJar(type : Jar ) {
14+ classifier = ' sources'
15+ from android. sourceSets. main. java. source
16+ }
17+
18+ artifacts {
19+ archives androidSourcesJar
20+ }
21+
22+ publishing {
23+ publications {
24+ release(MavenPublication ) {
25+ // The coordinates of the library, being set from variables that
26+ // we'll set up in a moment
27+ groupId publishGroupId
28+ artifactId publishArtifactId
29+ version libraryVersion
30+
31+ // Two artifacts, the `aar` and the sources
32+ artifact(" $buildDir /outputs/aar/${ project.getName()} -release.aar" )
33+ artifact androidSourcesJar
34+
35+ // Self-explanatory metadata for the most part
36+ pom {
37+ name = publishArtifactId
38+ description = libraryDescription
39+ // If your project has a dedicated site, use its URL here
40+ url = siteUrl
41+ licenses {
42+ license {
43+ name = licenseName
44+ url = licenseUrl
45+ }
46+ }
47+ developers {
48+ developer {
49+ id = developerId
50+ name = developerName
51+ email = developerEmail
52+ }
53+ }
54+ // Version control info, if you're using GitHub, follow the format as seen here
55+ scm {
56+ connection = scmConnection
57+ developerConnection = scmDeveloperConnection
58+ url = scmUrl
59+ }
60+ // A slightly hacky fix so that your POM will include any transitive dependencies
61+ // that your library builds upon
62+ withXml {
63+ def dependenciesNode = asNode(). appendNode(' dependencies' )
64+
65+ project. configurations. implementation. allDependencies. each {
66+ def dependencyNode = dependenciesNode. appendNode(' dependency' )
67+ dependencyNode. appendNode(' groupId' , it. group)
68+ dependencyNode. appendNode(' artifactId' , it. name)
69+ dependencyNode. appendNode(' version' , it. version)
70+ }
71+ }
72+ }
73+ }
74+ }
75+ repositories {
76+ // The repository to publish to, Sonatype/MavenCentral
77+ maven {
78+ // This is an arbitrary name, you may also use "mavencentral" or
79+ // any other name that's descriptive for you
80+ name = " sonatype"
81+
82+ def releasesRepoUrl = " https://oss.sonatype.org/service/local/staging/deploy/maven2/"
83+ def snapshotsRepoUrl = " https://oss.sonatype.org/content/repositories/snapshots/"
84+ // You only need this if you want to publish snapshots, otherwise just set the URL
85+ // to the release repo directly
86+ url = version. endsWith(' SNAPSHOT' ) ? snapshotsRepoUrl : releasesRepoUrl
87+
88+ // The username and password we've fetched earlier
89+ credentials {
90+ username ossrhUsername
91+ password ossrhPassword
92+ }
93+ }
94+ }
95+ }
96+ signing {
97+ sign publishing. publications
98+ }
99+
100+ nexusStaging {
101+ packageGroup publishGroupId
102+ stagingProfileId stagingProfileId
103+ username ossrhUsername
104+ password ossrhPassword
105+ }
106+ }
0 commit comments