I'm using maven-publish plugin to release an artifact to nexus repository. I don't want to put the actual credentials of my nexus repository in my build.gradle file. So I decided to use project properties like shown below
credentials {
username "$nexus_username"
password "$nexus_password"
}
Now I can use gradle publish -Pnexus_username=<myusername> -Pnexus_password=<mypass>
to publish my artifact to my nexus repository. But it doesn't make any sense to keep passing this project properties for a normal gradle build. And if I don't pass gradle is throwing an error saying Could not find property 'nexus_username'
Anybody know a better approach to solve this.
Using the -D command-line option, you can pass a system property to the JVM which runs Gradle. The -D option of the gradle command has the same effect as the -D option of the java command. You can also set system properties in gradle. properties files with the prefix systemProp.
In some cases when your Gradle files are deleted or corrupted you will not be able to download new Gradle files in android studio. In this case, we have to delete the Gradle files which are present already and then again sync your project to download our Gradle files again.
Found a solution after some digging
if(! hasProperty("nexus_username")){
ext.nexus_username=""
}
if(! hasProperty("nexus_password")){
ext.nexus_password=""
}
Here what I'm doing is creating a blank username and password if the project property is not available. But I still feel this is a work around and not the right solution. Please do respond if anybody find a more elegant solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With