Skip to content

Commit 5127b8a

Browse files
committed
Merge pull request #170 from alkemist/master
Configure the build to only use credential properties if uploading.
2 parents 64dc1e1 + f7dee62 commit 5127b8a

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

build.gradle

+20-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,26 @@ subprojects {
6262
uploadArchives {
6363
repositories {
6464
mavenDeployer {
65-
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2"){
66-
authentication(userName: "changeme", password: "changeme")
65+
gradle.taskGraph.whenReady { taskGraph ->
66+
if (taskGraph.hasTask(uploadArchives)) {
67+
def userProp = "sonatypeOssUsername"
68+
def passwordProp = "sonatypeOssPassword"
69+
def user = project.properties[userProp]
70+
def password = project.properties[passwordProp]
71+
72+
if (user == null || password == null) {
73+
throw new InvalidUserDataException(
74+
"Cannot perform $uploadArchives.path due to missing credentials.\n" +
75+
"Run with command line args `-P$userProp=«username» -P$passwordProp=«password»` or add these properties to $gradle.gradleUserHomeDir/gradle.properties.\n")
76+
}
77+
78+
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
79+
authentication(userName: user, password: password)
80+
}
81+
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
82+
authentication(userName: user, password: password)
83+
}
84+
}
6785
}
6886
}
6987
}

0 commit comments

Comments
 (0)