1616
1717apply plugin : ' maven-publish'
1818apply plugin : ' signing'
19+ apply plugin : ' com.gradleup.nmcp'
1920
2021Properties properties = new Properties ()
21- properties. load(project. rootProject. file(' local.properties' ). newDataInputStream())
22+ if (project. rootProject. file(' local.properties' ). exists()) {
23+ properties. load(project. rootProject. file(' local.properties' ). newDataInputStream())
24+ }
2225
2326def isReleaseBuild () {
2427 return libraryVersion. contains(" SNAPSHOT" ) == false
2528}
2629
27- def getReleaseRepositoryUrl () {
28- return hasProperty(' RELEASE_REPOSITORY_URL' ) ? RELEASE_REPOSITORY_URL
29- : " https://oss.sonatype.org/service/local/staging/deploy/maven2/"
30- }
30+ // Set the project version
31+ project. version = libraryVersion
3132
32- def getSnapshotRepositoryUrl () {
33- return hasProperty(' SNAPSHOT_REPOSITORY_URL' ) ? SNAPSHOT_REPOSITORY_URL
34- : " https://oss.sonatype.org/content/repositories/snapshots/"
35- }
36-
37- def getRepositoryUsername () {
38- return hasProperty(' NEXUS_USERNAME' ) ? NEXUS_USERNAME : " "
39- }
40-
41- def getRepositoryPassword () {
42- return hasProperty(' NEXUS_PASSWORD' ) ? NEXUS_PASSWORD : " "
43- }
44-
45- def keyID = properties. getProperty(" signing.keyId" )
46- def signing_password = properties. getProperty(" signing.password" )
47- def keyRingLocation = properties. getProperty(" signing.secretKeyRingFile" )
48- def nexus_username = properties. getProperty(" NEXUS_USERNAME" )
49- def nexus_password = properties. getProperty(" NEXUS_PASSWORD" )
33+ // Simple property lookup: local.properties first, then project properties (from ORG_GRADLE_PROJECT_* env vars)
34+ def keyID = properties. getProperty(" signing.keyId" ) ?: findProperty(' SIGNING_KEY_ID' )
35+ def signing_password = properties. getProperty(" signing.password" ) ?: findProperty(' SIGNING_PASSWORD' )
36+ def keyRingLocation = properties. getProperty(" signing.secretKeyRingFile" ) ?: findProperty(' SIGNING_SECRET_KEY_RING_FILE' )
37+ def sonatype_username = properties. getProperty(" SONATYPE_USERNAME" ) ?: findProperty(' SONATYPE_USERNAME' )
38+ def sonatype_password = properties. getProperty(" SONATYPE_PASSWORD" ) ?: findProperty(' SONATYPE_PASSWORD' )
5039
5140ext. " signing.keyId" = keyID
52- ext. " signing.secretKeyRingFile" = keyRingLocation
5341ext. " signing.password" = signing_password
5442
43+ // Set secretKeyRingFile if provided
44+ if (keyRingLocation) {
45+ ext. " signing.secretKeyRingFile" = keyRingLocation
46+ }
47+
5548publishing {
5649 publications {
5750 release(MavenPublication ) {
58- groupId = GROUP
59- artifactId = libraryName
60- version = libraryVersion
61-
6251 afterEvaluate {
52+ groupId = GROUP
53+ artifactId = libraryName
54+ version = libraryVersion
6355 from components. release
6456 }
6557
@@ -92,32 +84,17 @@ publishing {
9284 }
9385 }
9486 }
95- repositories {
96- maven {
97- name = " OSSRH"
98- url = isReleaseBuild() ? getReleaseRepositoryUrl() : getSnapshotRepositoryUrl()
99- credentials {
100- username = nexus_username
101- password = nexus_password
102- }
103- }
104- }
10587}
10688
10789signing {
108- required { isReleaseBuild() }
90+ required { isReleaseBuild() && keyID }
10991 sign publishing. publications. release
11092}
11193
112- tasks. register(' uploadArchives' ) {
113- dependsOn publishReleasePublicationToOSSRHRepository
114- }
115-
116- tasks. register(' androidSourcesJar' , Jar ) {
117- archiveClassifier = ' sources'
118- from android. sourceSets. main. java. sourceFiles
94+ nmcp {
95+ publishAllPublications {
96+ username = sonatype_username
97+ password = sonatype_password
98+ publicationType = " AUTOMATIC"
99+ }
119100}
120-
121- artifacts {
122- archives androidSourcesJar
123- }
0 commit comments