Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 301
dariobronx Avatar asked Apr 04 '16 15:04

dariobronx


People also ask

How do you pass properties in Gradle?

Using the -D command-line option, you can pass a system property to the JVM which runs Gradle. The -D option of the gradle command has the same effect as the -D option of the java command. You can also set system properties in gradle. properties files with the prefix systemProp.

How do I set environment variables in Gradle?

Click on Environment variables. After that, click the New option. Now, create user variable, enter the variable name as Gradle_Home and paste the value of the home path e.g., C:\gradle-6.0. 1 in the variable value field.


1 Answers

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']
like image 77
Michael Avatar answered Sep 30 '22 04:09

Michael