Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Properly set defaults for gradle properties

Having the following in build.gradle:

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "$repoUrl") {
                authentication(userName: "$repoUser", password: "$repoPassword")
            }
        }
    }
}

how can I make $repoUrl have a default value file://$buildDir/repo?

I tried to put repoUrl=file://$buildDir/repo in gradle.properties, but it doesn't work as I expected, as it seems that $repoUrl is not evaluated recursively.

like image 434
Tair Avatar asked Mar 15 '13 05:03

Tair


2 Answers

Looks like it is because repoUrl=file://$buildDir/repo is treated as plain string, without buildDir substitution.

If may try this:

repository(url: repoUrl.replace('$buildDir', "$buildDir")) {

Or something like this:

// run as 'gradle build -PreportUrl=blabla'
def repoUrl = "file://$buildDir/repo"
if (binding.variables.containsKey('repoUrl ')) {
 repoUrl = binding.variables.get('repoUrl ')
}
like image 156
Michail Nikolaev Avatar answered Nov 11 '22 06:11

Michail Nikolaev


You cannot reference Gradle properties like project.buildDir from properties files. Properties files are very limited, and in general, I'd recommend to keep all information in Gradle build scripts. You can have any number of build scripts, and include them with apply from: "path/to/script" in other scripts.

like image 23
Peter Niederwieser Avatar answered Nov 11 '22 07:11

Peter Niederwieser