Travis CI environment variables with Gradle properties

前端 未结 2 2209
攒了一身酷
攒了一身酷 2021-02-07 11:26

How can I use travis-ci env variables as Gradle\'s properties?

I locally have my gradle.properties under the gradle path having:

sonatypeRepo = abcd
         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-07 12:09

    I just stumbled on this too.

    This is how I got it to work:

    In my build.gradle

    def uzer = hasProperty('blahUser') ? blahUser : System.getenv('blahUser')
    def creds = hasProperty('blahPwd') ? blahPwd : System.getenv('blahPwd')
    

    In my $HOME/.gradle/gradle.properties

    blahUser=batman
    blahPwd=eatsworms
    

    So I needed this for travis-ci -- which I don't think has a notion of a $HOME/.gradle/gradle.properties But you can add environment variables to .travis.yml.

    Basically, as previously mentioned, if the property is 'there'; gradle uses it, otherwise asks the environment for it. In my case the 'hasProperty()' check was needed so travis wouldn't generate a property not found exception.....

    hth...

提交回复
热议问题