babbitt
babbitt

Reputation: 901

Gradle not picking up gradle.properties entry in init script

I'm trying to access a property that's set in ~/.gradle/gradle.properties from an init script distributed inside a custom gradle wrapper.

~/.gradle/gradle.properties

companyLogin=test

~/.gradle/wrapper/dists/.../companyLoginCheck.gradle

println "Company Username: " + companyLogin

This fails: "Could not find property 'companyLogin' on build.

projectRoot/buld.gradle

task printCompanyLogin {
    println "Company Username: " + companyLogin
}

This works fine (I have to comment out the init script one)

I am making sure I execute with $gradlew .

I've also tried putting companyLogin=test in the project root gradle.properties without success. Is this intentional behavior of Gradle? I don't recall seeing it in the manual, but I've not had as much time with Gradle in the last 6 months or so as I'd like.

Anyone have any suggestions?

Upvotes: 5

Views: 3203

Answers (1)

babbitt
babbitt

Reputation: 901

The issue was one of system properties vs project properties.

Init scripts run before the project is created, and therefor cannot access project properties.

Situation resolved with the following settings:

~/.gradle/gradle.properties

systemProp.company.login=test

~/.gradle/wrapper/dists/.../companyLoginCheck.gradle

final companyLogin = System.properties["company.login"]

Upvotes: 5

Related Questions