Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to know whether a certain dependency is compiled in the gradle file by returning a boolean

So the case is this, 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 know for instance whether the dependency A was used by returning a global boolean that can be used somewhere else, in a gradle task?

so in other words

if (A was compiled) {
      compile A;
} else {
      exclude A;
}
like image 745
Alex Goja Avatar asked Jul 12 '16 10:07

Alex Goja


1 Answers

You could get all compile dependencies like this:

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

It would return list of all dependencies in group:name:version format. Then you could just use:

if("org.codehaus.groovy:groovy-all:2.4.7" in compile) {
     println "org.codehaus.groovy:groovy-all:2.4.7 was compiled"
}
like image 86
Krzysztof Atłasik Avatar answered Sep 29 '22 02:09

Krzysztof Atłasik