Git gitignore pain :) sample scenario gradle.properties

This is the scenario:

New project, new IDE, you clone the project, Gradle fails, and you find out you are required to enter your credential in clear text into the gradle. properties… Keep reading 😉

What is required?

maven_user=YourUser

maven_pass=YourPasswordHere_BeCarfullDoNotCommitThisFileWithYourPass

BUT !

If the .gitignore file for the project does not have a line to exclude gradle.properties, the file will be listed as modified (which is correct), but you do not want to commit that change and make your credentials public.

Even if you go ahead and add the exclusion to the .gitignore the file will be included, but there is a fix.

.gitIgnore adding the exclusion

##Additional ignore

##Gradle properties due sensitive information to login

gradle.properties

git status

If you try a git status, you will notice gradle.properties is reported as modified even if you added it to the .gitignore file.

How to solve it

git rm -r –cached gradle.properties

Now gradle.properties changes have been removed from the cache, and you will be able to change them at any time without them being reported as modified since it is already on you . gitignoref file.

Additional Tip

II recommend adding a lot of blank lines so your credentials will not be visible if you open your gradle.properties in a call or when someone is looking at your screen, add some kind of warning, like:

##### WARNING YOUR PASSWORD IS ABOUT TO BE SEEN ####

##### WARNING YOUR PASSWORD IS ABOUT TO BE SEEN ####

That way, you will remember having that valuable information on the file any time you open it.

Final Note

Having maven_user and maven_pass on the project level is not the best option. Find your .gradle home directory, add gradle.properties there (if not already there), and add your desired configuration there, so you can forget about it once you have done it.

I hope you find this post useful.

Leave a comment