I have the following multi-module project structure.
Root project 'reports-be'
+--- Project ':auth'
+--- Project ':builder'
| +--- Project ':builder:base'
| \--- Project ':builder:reporting'
\--- Project ':common'
When I run build task for /builder subproject and I expect that build task will be executed for all subprojects (for :builder:base and :builder:reporting).
gradle clean :builder:build
But gradle execute build task only for subproject :builder.
According Gradle documentation build task should be completed for all subprojects.
Why doesn't it happen?
P.S. I found that the command gradle -p builder clean build works as I expected. But I really don't understand what is wrong with first mentioned gradle task.
P.S.S. I have build.gradle in every subproject and my settings.gradle looks like
rootProject.name = 'reports-be'
include 'common'
include 'builder'
include 'auth'
include 'builder:base'
include 'builder:reporting'
:builder:build is a qualified task name of the task build in the project :builder, so only this one task (and its dependencies) will be executed. The execution in all (sub-)projects is only possible for unqualified task names as build. You may switch to the builder directory and run gradle build from there, however this approach won't work if you want to run clean for all projects in the same invocation and it's kind of ugly when using the wrapper (gradlew). As far as I know, there is no direct solution for your use case.
If I get you right, the :builder project is just a dummy project for organization purposes and does not contain any actual sources or anything else to build. In this case, you may solve your problems using task dependencies inside builder/build.gradle:
task build {
dependsOn ':builder:base:build', ':builder:reporting:build'
}
Three possible solutions which I found:
1.
gradle -p builder clean build
2:
cd ./builder
gradle clean build
3. Add modification for builder/build.gradle (work for Gradle 6.3):
build {
dependsOn ':builder:base:build', ':builder:reporting:build'
}
And run gradle clean build from root project directory.
Thank you for this solution Lukas Korfer answer
Related
I want to clean all project of gradle,now I using this task in root project build.gradle:
task clean {
subprojects.each {
it.afterEvaluate {
def cleanTask = it.tasks.findByName('clean')
if (cleanTask) {
dependsOn(cleanTask)
}
}
}
}
it give me tips this clean task already exists,is there other way to do this task?I do not want to write many code like :
./gradlew clean projectA
./gradlew clean projectB
./gradlew clean projectC
Now I have more than 30 project.
There's a feature in Gradle where:
If you call a task on the root project
And the root project does not contain that task
A "proxy" task will be created in the root project
The "proxy" task will invoke any tasks with the same name in its subprojects
So usually, your subprojects will contain a "clean" task and your root project will not. So invoking "clean" on the root project will actually invoke "clean" on all the subprojects. I think this is the behavior you want?
If this is not occurring, it's likely you've created a "clean" task in your root project with different behavior (perhaps you applied the "base" plugin to the root project?). I suggest you remove the "clean" task from the root project
I'm trying to resolve dependency conflict in my gradle applicaiton. My top-level build.gradle is:
archivesBaseName = 'message-sender-rest'
apply plugin: 'paas-publish'
dependencies {
compile(project(':message-sender-api'))
compile(libraries.springBoot)
compile(libraries.loggingRuntime)
compile(libraries.integration)
compile(libraries.serviceFrameworkServer)
compile(libraries.serviceFrameworkApp)
compile(libraries.serviceFrameworkSpringIntegration)
testCompile(libraries.testing)
testCompile(libraries.springTest)
testCompile(libraries.activeMqBroker)
}
When I try to run gradle dependencyInsight --configuration compile, I get the following error:
* What went wrong:
Configuration with name 'compile' not found.
There is a whole bunch of lower level gradle files, but I guess that should just work using the top-level one, isn't it?
When i just try gradle dependencies, it returns pretty much nothing:
gradle dependencies
dockerBuild tag: dev.docker.orbitbenefits.capita/orbit/message-sender-rest:bOD-9656-ConfigServer-n0
:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
No configurations
BUILD SUCCESSFUL
Any idea what I may be missing?
I was not specifying the module I wanted to inspect:
The project had a sub-project (module message-sender-server). Specifying the module name actually worked:
gradlew message-sender-server:dependencyInsight --dependency webmvc
I have the following multiproject structure:
settings.gradle
rootProject.name = 'toolbox-backend'
include 'toolbox-components-rest'
include 'toolbox-components-executor'
include 'toolbox-components-toolsyncer'
I'd love to create a task in my root build.gradle which will call the clean, build, install (application) and finally the run task of the toolbox-components-rest submodule.
task startREST() {
dependsOn ':toolbox-components-rest:clean'
dependsOn ':toolbox-components-rest:build'
dependsOn ':toolbox-components-rest:bootRun'
println "[Toolbox $version] Starting REST interface..."
}
This does work - BUT the bootRun task is running before build which runs before clean. I'd like to have it exactly the other way around
Fixed the above with
bootRun.mustRunAfter build
build.mustRunAfter clean
in the gradle.build of the toolbox-components-rest submodule
Is there a way that makes gradle download dependency libraries to the project directory, just like maven does? I know that gradle keeps its own cache in local machine directory, but how can I know what libraries will be used for my project, especially the library I defined in the build.gradle file has its own dependency?
To know what libraries will be used for your project you can use dependencies task. It will help you to find out the dependencies of your module and its recursive dependencies.
If your module name is app, then you can try gradle :app:dependencies in the project directory. You'll get something like below as output.
compile - Classpath for compiling the main sources.
\--- com.android.support:appcompat-v7:22.2.0
\--- com.android.support:support-v4:22.2.0
\--- com.android.support:support-annotations:22.2.0
Here com.android.support:appcompact-v7:22.2.0 is dependency of the module and the one below is its recursive dependency.
If you really what to get the dependencies in your project directory, then you can create a task for it like this.
task copyDependencies(type: Copy) {
from configurations.compile
into 'dependencies'
}
now you can run gradle :app:copyDependencies to get all the dependencies in location <projectDir>/app/dependencies. Note that this just give you the dependencies in your project directory and gradle is still resolving the dependencies from the local cache.
I have multiple projects configured using build.gradle for each and settings.gradle at the top level.
I want to define or use a single Gradle task that will build all of the subprojects and the root.
How do I run or create a single Gradle task to run all subprojects and root in a multi-project build?
It depends on what all your projects are.
You can call gradle(w) build from the root dir if all your subprojects extend the javaplugin.
Other project types (like the ear plugin) need to be attached to the build task manually. The way I do this is by creating the build task like: task build and in the ear project: build.dependsOn ear