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?
Related
With Maven, I can print the build classpath with this command:
mvn dependency:build-classpath
Is there a similar command I can use with Gradle from the command line, preferably without having to modify any of the build scripts?
You can list all the dependencies in a configuration from CLI:
gradle dependencies --configuration=runtimeOnly
Or you can do that via a task:
task classPath {
doFirst {
configurations.runtimeOnly.each { println it }
// This should probably work as well:
// sourceSets.main.runtimeClasspath.each { println it}
}
}
I have a problem with build single module from Gradle multimodule project.
I have a structure:
-root-project:
-first-module
-second-module
-modules:
-first-submodule
-second-submodule
setting.gradle.kts
rootProject.name = "root"
include(
"first-module",
"second-module",
"modules",
"modules/first-submodule",
"modules/second-submodule"
)
When I run ./gradlew clean build, each module builds.
When I run ./gradlew first-module:clean first-module:build, builds only first-module.
But when I run ./gradlew modules:first-submodules:clean modules:first-build, I got error:
* What went wrong:
Project 'first-submodules' not found in project ':modules'.
Why?
I want to execute a gradle build command from build.gradle file.
build.gradle file
apply plugin: 'java'
apply plugin: 'application'
task me{
//Can we perform gradle build command here.
}
Question:
Can we perform gradle build command inside task me, similarly like we do from command prompt(screenshot attached)..?
Note : I am using windows env, please assume I am providing all other statements in build.gradle file.
I am able to build from command prompt by executing
.
I want to execute this task me from command prompt and it should be responsible to call gradle build command.(attached screenshot)
Yes, if you make the task me to a task of type GradleBuild
https://docs.gradle.org/current/dsl/org.gradle.api.tasks.GradleBuild.html
E.g.
task me(type: GradleBuild){
buildFile 'mybuild.gradle' //defaults to build.gradle so not needed
dir 'someDir'
tasks 'clean', 'build'
}
You cannot "call" a Gradle task in a Gradle build.
You might stumble upon the method execute() that each Gradle task has, but this is a purely internal method that must not be used by any build script. Using it will not work properly. It will not ensure the task is run only once, it will not ensure dependency tasks are run before and so on and so on, just don't use it.
Your code snippet is too big for me wanting to interpret it right now to understand what you want to do exactly, but if you want to "call" a Gradle task from another Gradle task, your logic is bogus and should be changed. If you want to run a Gradle task before or after another Gradle task is run, the only supported way is to use dependsOn (before) or finalizedBy (after) and you can not set these properties during execution phase of a task but only during configuration phase.
Well, there is one other way to call a Gradle task from a build script, but this is by using a task of type GradleBuild which would start a complete new and separate build of the project you specify which is most often not the action you really want to do.
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.
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