Avoid Build Repository Credentials in build.gradle


(Siva Jeganathan) #1

Hi, I created a gradle plugin and using it in my product build.gradle file. The plugin is consumed from Maven repository which requires authentication.

So I provided the following to make it work

buildscript {
  maven {
           credentials {  username "xyz@x.com" password "abc" }
           url 'corpMvnURL'

apply plugin:  "myplugin"

Now, the problem is including credentials in buildScript which is exposed to several audience. Is there any other way to avoid hardcoding of password in build.gradle file.

(uklance) #2

You can put properties in GRADLE_USER_HOME/gradle.properties or you can pass in properties from command line

eg gradle build -Puser=xxx -Ppassword=yyy

You can then access them in a gradle script via hasProperty(name), getProperty(name) and findProperty(name) methods (see Project javadocs)


repositories  {
  maven {
    credentials {  
      username getProperty('user') 
      password getProperty('password')