How can I execute ./gradlew assembleDebug crashlyticsUploadDistributionStageDebug from my custom task? I tried this code but it does not work:
task myTask {
doFirst {
tasks.assembleStageDebug().execute()
tasks.crashlyticsUploadDistributionStageDebug().execute()
}}
You should never execute tasks directly. Instead define dependencies between them:
task myTask
myTask.dependsOn assembleStageDebug, crashlyticsUploadDistributionStageDebug
Related
I use this gradle command to execute my UI-tests:
./gradlew connectedDebugAndroidTest -PUiTest
I want to define a custom gradle task that executes my UI-tests, so I could this:
task runUiTests() {
dependsOn("connectedDebugAndroidTest")
}
How can I pass the parameter -PUiTest in my custom gradle task to the connectedDebugAndroidTest task?
If taskB depends on taskA, when I execute task A and then taskB...
Question 1: Is taskA executed just once?
Question 2: Is it executed when I run taskA or when I run taskB?
Each Gradle task will only be executed once in a build (Gradle invocation).
Also, the task order you pass to Gradle will only be maintained, if there are no dependencies between them:
If you call gradle taskA taskB, but taskA.dependsOn taskB, taskB will be executed before taskA.
I have a simple project with subprojects and I want to generate aggregate report for all tests when I execute gradle test command.
I have followed the gradle documentation and added following:
task testReport(type: TestReport) {
// make sure this task is run after all subproject test tasks
mustRunAfter subprojects*.test
destinationDir = file("$buildDir/reports/allTests")
// Include the results from the `test` task in all subprojects
reportOn subprojects*.test
}
This works when I execute gradle test testReport, but when I execute gradle test or gradle build in the root project - the task testReport is not run.
How do make gradle to run the task without specifying it every time?
Add: test.finalizedBy 'testReport' to your build.gradle; just at the root level, doesn't have to be inside any closure.
taskX.finalizedBy taskY
Will run taskY everytime taskX completes execution successfully.
Trying to create a small custom gradle task for Spring Boot that originally looks like this:
gradle bootRun --debug-jvm
The task should look like this: gradle debugRun
I tried this but it does not work:
task debugRun(dependsOn: 'bootRun') << {
applicationDefaultJvmArgs = ['--debug-jvm']
}
How can I pass this debug-flag to the bootRun task?
It isn't sufficient for your debug run task to depend on the bootRun task. It needs to modify the existing bootRun task to enable debugging. You can do that by checking for the debugRun task in Gradle's task graph. If it's there, you set the bootRun task's debug property to true:
task debugRun(dependsOn:bootRun) {
gradle.taskGraph.whenReady { graph ->
if (graph.hasTask(debugRun)) {
bootRun {
debug = true
}
}
}
}
I have 2 gradle projects. Lets say projectA and projectB. I need to create a task in projectA, which can execute a task in projectB. I tried with many ways, but i couldn't find a way to do that. Consider following code,
//ProjectA build.gradle
task taskA(dependsOn: ProjectB.taskB) << { println "executed taskB" }
//ProjectB build.gradle
task taskB() << { println "executing taskB"}
when I run taskA output should be,
>> gradle taskA
executing taskB
executed taskB
Can I anyhow achieve this?
thanks.
task taskA(dependsOn: project(":ProjectB").taskB)
We don't say that taskA executes taskB but that it depends on taskB.