dariobronx
dariobronx

Reputation: 395

gradle.properties fail reading property with dot notation

I receive an error reading a property with dot notation from gradle.properties. Why?

If I use version instead of build.version everything is OK. Thanks in advance.

FAIL CASE

gradle.properties

build.version=2.0.1

build.gradle

apply plugin: 'java'

task testProperties << {
    println "***************** TEST **********************"
    println build.version
    println "*********************************************"
}

EXECUTION

... $ gradle devTest
:devTest
***************** TEST **********************
:devTest FAILED

FAILURE: Build failed with an exception.

* Where:
Build file '..../build.gradle' line: 50

* What went wrong:
Execution failed for task ':devTest'.
> Could not find property 'version' on task ':build'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or<br> --debug option to get more log output.

BUILD FAILED

SUCCES CASE

gradle.properties

version=2.0.1

build.gradle

apply plugin: 'java'

task testProperties << {
    println "***************** TEST **********************"
    println version
    println "*********************************************"
}

EXECUTION

... $ gradle devTest

:devTest

***************** TEST **********************
2.0.1

*********************************************

BUILD SUCCESSFUL

Upvotes: 19

Views: 6911

Answers (3)

Ruslan Stelmachenko
Ruslan Stelmachenko

Reputation: 5420

And another one:

println property('build.version')
println "Version: ${property('build.version')}"

or

println ext['build.version']
println "Version: ${ext['build.version']}"

See Properties and Extra Properties documentation.

Upvotes: 2

Li Chao
Li Chao

Reputation: 336

Another way to get access to the properties is using syntax below

println "Version: ${project.'build.version'}"

Upvotes: 18

Michael
Michael

Reputation: 54705

You cannot use properties with a dot in this way because Groovy thinks it's a version property of the build instance. If you want a property to contain a dot then you should use it in the following way:

println rootProject.properties['build.version']

Upvotes: 23

Related Questions