Gradle Build single module - gradle

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?

Related

Building and running an executable jar of spock groovy scripts

I have a multi-module Gradle application:
root setting.gralde.kts:
include(
":common-config-qa",
":app-spock-tests",
)
the common-config-qa application contains
main spock-groovy code which sets up required data for the tests to be executed.
java util classes
the app-spock-tests contains spock-groovy code to run spock tests for multiple apps separated into each folder.
When I execute ./gradlew clean test the tests are getting executed.
I tried to create an executable jar out of this project by specifying the following in the build.gradle.kts file under common-config-qa project:
application {
mainClass.set("com.test.qa.CommonSpockSpec")
}
tasks.jar {
manifest {
attributes(mapOf("Implementation-Title" to project.name,
"Implementation-Version" to project.version))
}
}
Also included the plugin: id("com.github.johnrengelman.shadow") version "7.1.2" to create a shadow jar.
I included the same plugin on the other app.
The uber-jar is getting created but when I execute the command from the root folder:
./gradlew jar common-config-qa/build/libs/common-config-qa-0.1-all.jar: I am getting the error as
FAILURE: Build failed with an exception.
* What went wrong:
Task 'common-config-qa/build/libs/common-config-qa-0.1-all.jar' not found in root project 'root-spock-project'.
If I execute the same command from inside the folder common-config-qa, I am getting the error as:
* What went wrong:
Task 'build/libs/common-config-qa-0.1-all.jar' not found in root project 'common-config-qa'.
I would like to have a jar which I can use to execute the tests from command line. How can I get an executable jar for this application and its runs properly.

Gradle project dependency problems

I have a multi-project Gradle build that is configured as this:
keycloak
|-- keycloak-spi-1
|-- keycloak-spi-2
|-- keycloak-theme
the subprojects build jars that i want to include inside docker that is build in the parent with Jib but, an error message appears:
Obtaining project build output files failed
Gradle is version 7.4.1
Thanks
After some investigation, Jib use the output of jar task during the image build and, in this case, jar task must not compile sources but copy the shadowJars from all the subprojects. I take this approach but not work:
task jar(type: Jar, overwrite: true) {
subprojects {
from(tasks.shadowJar)
}
into "${buildDir}/libs"
doLast {
delete jar.archiveFile
}
}

Gradle task don't run in all subprojects

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

Gradle: Dependency insight report cannot be generated because the input configuration was not specified

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

Execute a Task of a sub-module of a Gradle multiproject

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

Resources