How to access list of values from gradle.properties to build.gradle


(shaik) #1

I am having the following properties in gradle.properties

gradle.properties

version=2.1

paths=[’/home/desk/hie’, ‘/home/mydesk1/hai1’, ‘/home/mydesk2/hai2’]

sources=[’/src/path/impl’, ‘/src/path/src’]

I need to access these paths and sources form gradle.properties to build.gradle

build.gradle

sourceSets {

main {

    java {

        srcDir=${paths}

    }

}

}

but ‘${paths}’ is not working.

Can you someone help to get out of this issue and how to use those list in build.gradle file


(Chris Beams) #2

Hi @imran1,

There are a couple issues here.

The first is that you’re using GString interpolation syntax (${...}) in your assignment to the srcDir property. Simply remove the braces and you should be good to go.

The second is that you’re attempting to assign the value to the srcDir property, but since you’re dealing with a list of values, you should actually use srcDirs instead (in fact, you should pretty much always favor srcDirs).

Like this:

sourceSets {
    main {
        java {
            srcDirs = paths
        }
    }
}

Your gradle.properties file should not need to be changed at all for the above to work.

In the future, please include the error message that Gradle gives you at the command line. That helps us troubleshoot more quickly. Also, please use the triple-backtick syntax (```) for code blocks and single-backticks to better clarify program elements, for example, ${paths}.


(shaik) #3

Thanks but the above approach is giving some errors as below

gralde.properties
paths=[‘com.xxx.xxx.xxx…SiteAdminService’,‘com.xxx.xxx.xxx.rest.LoginFacadeService’,‘com.xxx.xxx.xxx.rest.LoginSiteApiService’]

build.gradle
filter {
excludes = paths
}

output:

Cannot cast object ‘[‘com.xxx.xxx.xxx…SiteAdminService’,‘com.xxx.xxx.xxx.rest.LoginFacadeService’,‘com.xxx.xxx.xxx.rest.LoginSiteApiService’]’ with class ‘java.lang.String’ to class ‘java.util.List’

actually I need these paths to be replaced in the below format in build.gradle

filter {
excludes =[‘com.xxx.xxx.xxx…SiteAdminService’,‘com.xxx.xxx.xxx.rest.LoginFacadeService’,‘com.xxx.xxx.xxx.rest.LoginSiteApiService’]
}

can you please figure out is there any issue here