Refer properties within gradle.properties


(Nishant Agarwal) #1

//file gradle.properties var1 = abcd var2 = var1

//file build.gradle println var2

//output var1

//Problem: I want to assign the value of var1 to var2. Can you please a way to do that

Thanks, Nishant.


(Peter Niederwieser) #2

There is no way to do this, as ‘gradle.properties’ is a plain properties file. I recommend to set the values in a Gradle build script instead.


(Nishant Agarwal) #3

These properties are going to be used across multiple build files. And I want to avoid the overhead of changing it in every file, whenever required.


(Peter Niederwieser) #4

You can set them as extra properties (‘ext.var1 = “abcd”’) in the root build script or a script plugin. There is no way to achieve what you want with properties files.


(Nishant Agarwal) #5

Thanks Peter.

I will try that.


(Nishant Agarwal) #6

One last question,

So, my structure is roughly like this source

  • build.gradle

  • gradle.properties

— dir1

— dir2

— dir3

I create dir1, dir2, etc directories (and several subdirectories with in them at runtime). For which I declare a “project.home” variable. And for each subdir dir1 = ${project.home}\dir1

Note: I will use this properties for executing ANT tasks like ant.mkdir(dir: dir1)

This setup works for Ant. But as you have mentioned gradle properties is plain file and does not support such setup.

What would be the optimal alternative for this. (init script, ant.properties(), extra properties, or any other)?

Thanks, Nishant.