Refer properties within gradle.properties

//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.

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.

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.

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.

Thanks Peter.

I will try that.

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.