I'm currently executing all my Gradle build tasks with the commands:
task runAll {
dependsOn tasks.withType(JavaCPPTask)
}
build.dependsOn.add("runAll")
I can run clean on individual tasks by running:
gradle cleanTaskName
How can I adapt the generic clean target to run for all my tasks as I do for the build target?
TIA
Related
command line ./gradlew -P foo.
I want to complete the build.gradle script when the above command is executed, but I am at a loss because there is no documentation.
// build .gradle
if (hasProperty('foo')) {
// run build like ./gradlew clean build
}
how can run build in build.gradle script?
When executing gradle build in a composite gradle build only compileJava task is executed transitively. Others, like the test task are not.
How can I enforce that my tests are also run on build?
I tried:
build.dependsOn gradle.includedBuilds*.task(':build')
but that did not work.
https://docs.gradle.org/current/userguide/composite_builds.html
here is the gist:
// settings
if (file('../myModule').exists()) {
includeBuild('../myModule')
}
// build1
dependencies {
compile 'mygroup:MyModule:1.0.0'
}
I have 5 projects that are dependent. So I have made new 'dummy' project that is a composite build of these 5 projects and have the following task:
task build {
dependsOn gradle.includedBuilds*.task(':build')
}
I can run the build of all projects in composite using: gradlew build? Or how to this in other way?
How can I now pass the -x test to skip the test execution for composite build?
Instead of trying to exclude tasks (build tasks depend on test), you can use the assemble task instead:
task buildWithoutTests {
dependsOn gradle.includedBuilds*.task(':assemble')
}
According to the task listing (gradle tasks), the difference is:
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
I have a traditional java project using gradle build system.
I would like to add jacoco code coverage report generation. So I applied jacoco plugin and everything works as expected when I call gradle build jacocoTestReport
I was wondering how can I define in my build.gradle script that jacocoTestReport task should run automatically after buildtask has been finished.
The goal is to only run gradle build from command line and this will automatically execute test and jacocoTestReport (so that I don't have to pass jacocoTestReport as commandline parameter explicitly).
I would suggest
build.finalizedBy(jacocoTestReport)
This way, the jacocoTestReport task is only executed after the build task, as you specified. In the accepted answer, the build task depends on the test report task, which means build will be executed after your custom task.
Add this to the end of your buildscript
build.dependsOn jacocoTestReport
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.