Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why gradle is throwing error on missing project property

Tags:

gradle

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.

like image 508
Thomas Avatar asked May 19 '15 13:05

Thomas


People also ask

How do I pass project property in gradle?

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.

Why is my gradle build failing?

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.


1 Answers

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.

like image 96
Thomas Avatar answered Nov 15 '22 12:11

Thomas