16
16
17
17
apply plugin : ' maven-publish'
18
18
apply plugin : ' signing'
19
+ apply plugin : ' com.gradleup.nmcp'
19
20
20
21
Properties 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
+ }
22
25
23
26
def isReleaseBuild () {
24
27
return libraryVersion. contains(" SNAPSHOT" ) == false
25
28
}
26
29
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
31
32
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' )
50
39
51
40
ext. " signing.keyId" = keyID
52
- ext. " signing.secretKeyRingFile" = keyRingLocation
53
41
ext. " signing.password" = signing_password
54
42
43
+ // Set secretKeyRingFile if provided
44
+ if (keyRingLocation) {
45
+ ext. " signing.secretKeyRingFile" = keyRingLocation
46
+ }
47
+
55
48
publishing {
56
49
publications {
57
50
release(MavenPublication ) {
58
- groupId = GROUP
59
- artifactId = libraryName
60
- version = libraryVersion
61
-
62
51
afterEvaluate {
52
+ groupId = GROUP
53
+ artifactId = libraryName
54
+ version = libraryVersion
63
55
from components. release
64
56
}
65
57
@@ -92,32 +84,17 @@ publishing {
92
84
}
93
85
}
94
86
}
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
- }
105
87
}
106
88
107
89
signing {
108
- required { isReleaseBuild() }
90
+ required { isReleaseBuild() && keyID }
109
91
sign publishing. publications. release
110
92
}
111
93
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
+ }
119
100
}
120
-
121
- artifacts {
122
- archives androidSourcesJar
123
- }
0 commit comments