This is how I solved the problem at the moment. This is not an ideal solution, but so far it is good enough.
Update!
I updated the answer to include the latest 0.9.2 Gradle plugin and new (est) functions (basically only updated library build scripts).
root: gradle.build
// global variables ext { // can be set to default values or blank groupFreePro = "free" } // start parameters println "Start parametes: tasks = " + gradle.startParameter.getTaskNames() gradle.startParameter.getTaskNames().each { task -> if (task.contains("Free") || task.contains("F")) { groupFreePro = "free" } else if (task.contains("Pro") || task.contains("P")) { groupFreePro = "pro" } println "groupFreePro = " + groupFreePro } android { ... }
task.contains("F") should handle shortened versions or tasks that are being executed (if we want to run the script as a gradle aFD ).
Global variables in ext can be set to default values. In this case, even if you run the script without "Free / Pro" in the task name, it should work fine. The disadvantage of the default values โโis that the assembly may not work if it is not configured properly (if you want the assembly to work only if the name "Free / Pro" is specified in the task name).
library: gradle.build
android { ... defaultPublishConfig groupFreePro + groupDebugRelease.capitalize() productFlavors { free pro } ... sourceSets { main { java.srcDirs = ['/src'] res.srcDirs = ['/res'] } free { java.srcDirs = ["free/src"] res.srcDirs = ["free/res"] } pro { java.srcDirs = ["pro/src"] res.srcDirs = ["pro/res"] } } ... } dependencies { freeCompile fileTree(dir: 'free/lib', include: '*.jar') }
Update:
The library now contains
defaultPublishConfig , so I don't need to specify
java.srcDirs = ["src", groupFreePro + "/src"] res.srcDirs = [groupFreePro + "/res"]
as well as compilation of user taste, i.e. flavor1Compile (in the dependencies block).
The ability to write compile project(path: ':project', configuration: 'flavor1Debug') in the dependencies block doesn't really work for us, because you have to pass these parameters through dependencies, and if you have several taste groups / dimensions, this means that more or less all flavor combinations must be processed in "not the last" dependencies (ie dependencies that have other dependencies (which have several flavorings)).
The println lines are just to see and make sure that the correct parameters are passed.
The surface of this solution (compared to Varun's) is that you only need to run one (original) task. It also means that it works (or at least should) with Android Studio without any problems.
The disadvantage of this solution is that it does not work if you want to create all the options using the gradle assemble command (or similar), which does not contain part of the Free task. I think that this could also be handled, but I am not doing it because the current solution is good enough for me now (although if I improve the current solution I will probably also update this answer).
There are other solutions using gradle.taskGraph.whenReady , but I don't know how to install srcDirs (dependencies in particular) correctly. Suggestions are welcome.