Reputation: 5734
I want to run
./gradlew extractMyDeps
instead of
./gradlew :app:dependencies --configuration productionDebugRuntimeClasspath
but I can't pass args to this task via dependOn
How to achieve my goal?
task("extractMyDeps") {
dependsOn(":app:dependencies") // how pass --configuration
}
Upvotes: 2
Views: 881
Reputation: 389
I think you can't pass the command line arguments to another task. But if you want to make an alias for a task you can use Exec Tasks like this:
task('extractMyDeps', type: Exec) {
workingDir '..'
def arguments = ['cmd', '/c', 'gradlew', ':app:dependencies', '--configuration', 'testCompileClasspath']
commandLine arguments
}
By using this task, you can run:
> gradlew extractMyDeps
Also you can make it more dynamic by passing the configuration name like this:
task('extractMyDeps', type: Exec) {
workingDir '..'
def arguments = ['cmd', '/c', 'gradlew', ':app:dependencies']
if (project.hasProperty("conf")) {
def conf = project.property("conf")
arguments.add('--configuration')
arguments.add(conf.toString())
}
commandLine arguments
}
This way these commands are valid:
> gradlew extractMyDeps
> gradlew extractMyDeps -Pconf=testCompileClasspath
I hope it will help you.
Upvotes: 1