Is there a way to find out if a specific dependency in the gradle file is compiled by returning a boolean

So, in this case, in the build.gradle file in the dependency structure I have

dependencies { compile 'A' compile 'B' } 

However, I want people to be able to compile either just A or just B, is there a way to find out if the A dependency was used, returning a global boolean that could be used somewhere else, in the gradle task?

so in other words

 if (A was compiled) { compile A; } else { exclude A; } 
+7
android android-gradle groovy build.gradle gradle
source share
1 answer

You can get all the compilation dependencies as follows:

 def compile = configurations.compile.allDependencies*.with{"$it.group:$it.name:$it.version".toString()} 

It will return a list of all the dependencies in the format group:name:version . Then you can simply use:

 if("org.codehaus.groovy:groovy-all:2.4.7" in compile) { println "org.codehaus.groovy:groovy-all:2.4.7 was compiled" } 
+1
source share

All Articles