Jacoco Report Aggregation Plugin - Spring Dependency Management - spring-boot

I’m doing a migration of aggregated code coverage from script Reporting code coverage with JaCoCo Sample to The JaCoCo Report Aggregation Plugin
This is a SpringBoot project and as it’s or it was a common practice, it uses Dependency Management Plugin.
After I run testCodeCoverageReport task to aggregate test reports I get following exceptions. I assume this is because I use BOM and dependency version constraint from within dependencyManagement instead of native Gradle dependency constraints.
Exception below:
Execution failed for task ':testCodeCoverageReport'.
Could not resolve all files for configuration ':allCodeCoverageReportClassDirectories'.
Could not find com.pizza.infrastructure:logging:.
Required by:
project : > project :pizza-server
Could not find com.pizza.infrastructure:multitenancy:.
Required by:
project : > project :pizza-server
Could not find com.pizza.infrastructure:rest:.
Required by:
project : > project :pizza-server
project : > project :pizza-server > project :pizza-rest
Could not find com.pizza.infrastructure:rest-test:.
Required by:
project : > project :pizza-server
Is there a solution, to be able to still rely on dependencyManagement plugin and also be able to use jacoco aggregation plugin?

Perhaps not ideal, but I have the following plugin block in my build.gradle.kts for my 'test-results' module to resolve spring related dependencies, by adding the last two gradle plugins
plugins {
id("jacoco-report-aggregation")
id("test-report-aggregation")
id("org.springframework.boot") version "2.6.6"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
}

Related

Gradle: Could not resolve all files for configuration ':compileClasspath'

Gradle build is throwing the following error
What went wrong:
Execution failed for task ':compileJava'.
Could not resolve all files for configuration ':compileClasspath'.
Could not find com.oracle:ons:19.3.
Required by:
project :
project : > com.xyz.abc.utils:openshift-utils:2.0.30
I have added the below dependency
implementation('com.oracle:ons:19.3')
Also the below repository
mavenCentral()
maven { url 'http://repository.xyz.com:8081/artifactory/gradle-plugins'; allowInsecureProtocol true
metadataSources {
mavenPom()
artifact()
}
}
I can see this dependency under Project and External Dependencies
The project that is needing this dependency has the below line in build.gradle
compile("com.oracle:ons:19.3")
I'm using gradle wrapper and gradle version is 7.4.2
Can you please help in resolving this error?
I was also facing similar issue. This resolved for me when I used a compatible spring boot version for particular JAVA version you are using in your project.I was getting similar issue-
For example - version 3.0.0 is not compatible with JAVA 11
But when I used version 3.0.0 with JAVA 17 and rebuild the project, it was resolved

Library version in gradle downgraded

When executing (in gradle 6.5)
./gradlew dependencyInsight --dependency groovy-testng --configuration testRuntimeClasspath
I could find groovy-testng comes from groovy-all library which was added to our build.gradle. I wanted to update version of groovy-testng, so I decided to update groovy-all which, according to mvnrepository, contains groovy-testng in version 3.0.4, but still the version of groovy-testng was the old one and gradle didn't resolve it to the latest version:
org.codehaus.groovy:groovy-testng:2.5.12 (selected by rule)
variant "runtime" [
org.gradle.status = release (not requested)
org.gradle.usage = java-runtime
org.gradle.libraryelements = jar
org.gradle.category = library
Requested attributes not found in the selected variant:
org.gradle.dependency.bundling = external
org.gradle.jvm.version = 11
]
org.codehaus.groovy:groovy-testng:3.0.4 -> 2.5.12
\--- org.codehaus.groovy:groovy-all:3.0.4
\--- testRuntimeClasspath
I have found the line selected by rule but couldn't find any ResolutionStrategy in my project, so I started to comment out and see what causes this. It turned out it's a plugin org.springframework.boot together with io.spring.dependency-management causes this version to be downgraded. Why? And why only when both of them are included? I assume these plugins define some ResolutionStrategy? What is the easiest way to find out where is the ResolutionStrategy coming from?
The Spring Dependency Management plugin is rather heavy handed. If were you build your project with --info or -i, you will see a bunch of these logs:
Applying dependency management to configuration 'bootArchives' in project 'demo'
Applying dependency management to configuration 'archives' in project 'demo'
Applying dependency management to configuration 'default' in project 'demo'
Applying dependency management to configuration 'compile' in project 'demo'
Applying dependency management to configuration 'implementation' in project 'demo'
Applying dependency management to configuration 'runtime' in project 'demo'
Applying dependency management to configuration 'compileOnly' in project 'demo'
From my experience, the dependency management plugin will win/force itself to win.
I can see in your snippet, that you wanted 3.0.4 of Groovy, but Gradle resolved 2.5.12. If you look at the Spring Boot Dependencies BOM, you will see that 2.5.12 is the current version for Spring Boot 2.3.1: https://github.com/spring-projects/spring-boot/blob/2.3.x/spring-boot-project/spring-boot-dependencies/build.gradle#L365..L371
The Spring Boot Gradle plugin detects if the Spring dependency management plugin is present, and if so, configures the plugin to import the Spring Boot dependencies BOM: https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/DependencyManagementPluginAction.java
From looking at the BOM: https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-dependencies/2.3.1.RELEASE/spring-boot-dependencies-2.3.1.RELEASE.pom
You should be able to override the Groovy version like so:
ext {
set("groovy.version", "3.0.4")
}
The Spring dependency management plugin should pick that up and apply 3.0.4
If that doesn't solve your issue, then you have other plugins or configuration at play here that you will need to figure out.
I also suggest watching Managing Dependencies for Spring Projects with Gradle to learn the differences between Spring dependency management plugin and Gradle's native dependency management.

Gradle dependency of modules in intellij

I have 2 modules in an intellij project..One intellij plugin module and another one is an gradle module.
I need to call a class of the plugin module from the gradle module..I did add dependency of module by following this path: Project structure->module->Module dependency.But it is not resolved.
I have also added the below code in:
settings.gradle
include ':Change',':module'
build.gradle
dependencies{
compile project (:Change)
}
Here 'Change' is the name of the intellij plugin module.
Every time I try to build the gradle it throws below error:
Could not determine the dependencies of task ':distTar'.
Could not resolve all task dependencies for configuration ':runtimeClasspath'.
> Could not resolve project :ChangeImpactAnalysis.
Required by:
project :
> Unable to find a matching configuration of project :ChangeImpactAnalysis: None of the consumable configurations have attributes.
Please help

Kotlin buildSrc failing on Gradle 4.10 due to missing dependency

When upgrading to Gradle 4.10, I faced the following error when attempting to compile:
Execution failed for task ':buildSrc:compileKotlin'.
> Could not resolve all files for configuration ':buildSrc:kotlinCompilerPluginClasspath'.
> Could not find org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.2.60.
Searched in the following locations: file:/Users/<user-name>/.gradle/caches/4.10/embedded-kotlin-repo-1.2.60-2/repo/org/jetbrains/kotlin/kotlin-scripting-compiler-embeddable/1.2.60/kotlin-scripting-compiler-embeddable-1.2.60.jar
Required by:
project :buildSrc
> Could not find org.jetbrains.kotlin:kotlin-sam-with-receiver:1.2.60.
Required by:
project :buildSrc
Note that I was using buildSrc as part of my Gradle compilation process.
This is due to a breaking change in Kotlin DSL 1.0:
The kotlin-dsl plugin now requires a repository to be declared
With Kotlin 1.2.60, the Kotlin Gradle Plugin driving the kotlin compiler requires extra dependencies that aren't required by Gradle Kotlin DSL scripts alone and aren't embedded into Gradle.
This can be fixed by adding a repository that contains Kotlin compiler dependencies on the project where the kotlin-dsl plugin is applied: repositories { jcenter() }
build.gradle.kts should contain
plugins {
`kotlin-dsl`
}
// Required since Gradle 4.10+.
repositories {
jcenter()
}

Fails to resolve dependency for a sub-module with spring boot plugin

I use gradle, and has a module/project that has spring boot plugin applied. Lets Say in a project sub-module, I have apply plugin: "spring-boot".
Now from a another module/project I am adding a testCompile dependency to the sub-module. Say from another project main-module, I have added the below dependency
dependencies {
testCompile project(":sub-module")
}
But when I test compile main-module, I get the below error,
* What went wrong:
Could not resolve all dependencies for configuration ':main-module:testCompile'.
> Could not find org.springframework.boot:spring-boot-starter-logging:.
Searched in the following locations:
https://jcenter.bintray.com/org/springframework/boot/spring-boot-starter-logging//spring-boot-starter-logging-.pom
https://jcenter.bintray.com/org/springframework/boot/spring-boot-starter-logging//spring-boot-starter-logging-.jar
Required by:
com.xx.xx-main-module:1.0-SNAPSHOT > com.xx.xx:sub-module:1.0-SNAPSHOT
> Could not find org.springframework.boot:spring-boot-starter-data-solr:.
Searched in the following locations:
https://jcenter.bintray.com/org/springframework/boot/spring-boot-starter-data-solr//spring-boot-starter-data-solr-.pom
https://jcenter.bintray.com/org/springframework/boot/spring-boot-starter-data-solr//spring-boot-starter-data-solr-.jar
Required by:
com.xx.xx:main-module:1.0-SNAPSHOT > com.xx.xx:sub-module:1.0-SNAPSHOT
The above error implies that I need to apply spring-boot in main-module as well and have all the buildScript dependencies to spring repos in the main-module build.gradle.
Just seems wrong that main-module has to declare plugins and dependencies that it is least bothered about.
Gradle version : 2.10
Spring-boot version : 1.3.2.RELEASE

Resources