Failure on reading non-existent property...how to avoid this?

Naturally, we want people to be able to checkout our gradle project and run ./gradlew assemble with no errors. We have build file that defines a repo that most users don’t need and don’t have the passwords for. I either want to fill these props in with empty string username/password or have it non-existent when they run it. The code is like so

Gradle 5.3.1

publishing {
repositories {
maven {
name = ‘sonatype’
url = “https://oss.sonatype.org/service/local/staging/deploy/maven2/
credentials {
username = sonatypeUsername
password = sonatypePassword
}
}
maven {
name = ‘myTemp’
url = “file:/tmp/myRepo/”
}
}

How can I have it so this credentials section doesn’t happen maybe? or how should I do this? Currently, the github autobuild is failing :frowning: since it doesn’t have username and password.

if(project.properties.sonatypeUsername && project.properties.sonatypePassword) {
  publishing.repositories.maven {
     name = 'sonatype'
     url = '.......'
     username = project.properties.sonatypeUsername
     password = project.properties.sonatypePassword
  }
}
1 Like

Thanks for your nice tips.

1 Like

btw. thanks!! that worked GREAT!!