Reputation: 20182
I am using gradle v3.4 and have populated properties from a secrets.properties file (passed into project.ext) but when I use the variables in the credentials section, I get an error from nexus complianing about authentication issues which makes me believe the string interpolation is not working correctly. I can print the variable value just before the credentials section.
build.gradle
maven {
credentials {
println(project.nexusUsername) //prints the value
username '${project.nexusUsername}'
password '${project.nexusPassword}'
}
if (project.version.endsWith("-SNAPSHOT")) {
url "http://nexus.somewhere.com/repository/some-java-snapshot/"
} else {
url "http://nexus.somewhere.com/repository/some-java-release/"
}
}
Update I updated the credentials section above to use double quotes (not single) but that did not solve the issue. Single quotes are String literals - if you need String interpolation, you need to use double quotes in groovy.
Upvotes: 18
Views: 17348
Reputation: 20182
The issue was how the properties was specified in the external properties file. I was using double quotes for the String values in the properties file and that was resulting in authentication failures. Once I removed the double quotes from the external properties file, I was able to publish to nexus.
Incorrect external properties file setting
someUsername="someuser"
Correct external properties file setting
someUsername=someuser
build.gradle
publishing {
publications {
shadow(MavenPublication) {
from components.shadow
groupId project.group
artifactId project.artifactId
}
}
repositories {
maven {
credentials {
username project.someUsername
password project.somePassword
}
if (project.version.endsWith("-SNAPSHOT")) {
url project.someSnapshot
} else {
url project.someRelease
}
}
}
}
this works.
Upvotes: 27
Reputation: 841
Single quotes denote a String literal without variable expansion;
Please use
username project.nexusUsername
password project.nexusPassword
Reference: http://docs.groovy-lang.org/latest/html/documentation/#_single_quoted_string
Upvotes: 3