Skip to content

Commit 66d1106

Browse files
authored
Load sonatype credentials from properties. (#516)
Avoids storing credentials in plain text
1 parent 5025c0b commit 66d1106

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

buildSrc/src/main/groovy/com.google.api-ads.java-conventions.gradle

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* These are shared settings common to all Google Ads Java library subprojects.
1717
*/
1818

19+
1920
import org.gradle.api.DefaultTask
2021
import groovy.io.FileType
2122
import groovy.io.FileVisitResult
@@ -55,8 +56,6 @@ javadoc {
5556
options.addStringOption('Xdoclint:none', '-quiet')
5657
}
5758

58-
final def sonatypeCredentialsConfig = file(System.properties['user.home'] + '/.sonatype-creds')
59-
6059
publishing {
6160
publications {
6261
maven(MavenPublication) {
@@ -67,14 +66,11 @@ publishing {
6766
maven {
6867
url 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
6968
name = "sonatype"
70-
71-
if (sonatypeCredentialsConfig.exists()) {
72-
def props = new Properties()
73-
sonatypeCredentialsConfig.withInputStream { props.load(it) }
74-
credentials {
75-
username props['username']
76-
password props['password']
77-
}
69+
credentials {
70+
// Avoids storing Sonatype credentials in plain-text. Specify these on
71+
// the command line: -PsonatypeUser=foo
72+
username project.properties.get("sonatypeUser")
73+
password project.properties.get("sonatypePassword")
7874
}
7975
}
8076
}
@@ -84,8 +80,13 @@ publishing {
8480
tasks.findAll {
8581
if (it.name.matches("publish.+ToSonatypeRepository")) {
8682
it.doFirst {
87-
if (!sonatypeCredentialsConfig.exists()) {
88-
throw new GradleException("Unable to load Sonatype credentials from ${sonatypeCredentialsConfig}.")
83+
def user = project.properties.get("sonatypeUser")
84+
def pass = project.properties.get("sonatypePassword")
85+
if (user == null || user.length() == 0) {
86+
throw new GradleException("Missing property for sonatype username, try -PsonatypeUser=foo")
87+
}
88+
if (pass == null || pass.length() == 0) {
89+
throw new GradleException("Missing property for sonatype password, try -PsonatypePassword=foo")
8990
}
9091
}
9192
}

0 commit comments

Comments
 (0)