исключить apiguardian-api из конфигурации junitPlatform в Gradle 6
Я пытаюсь запустить jacoco в моей сборке на основе Gradle 6.0.1. Это многопроектная сборка. (полный файл build.gradle в конце этого вопроса)
Моя конечная цель - запускать отчеты jacoco с помощью моей многопроектной сборки Gradle с использованием junit 5 и Gradle 6.
У меня почти все работает, но это требует, чтобы я выключился failOnVersionConflict
чего я действительно не хочу делать. Вместо этого я предпочитаю исключать зависимости от случая к случаю. Опыт подсказывает мне, что не полагаться на совместимость версий, подразумеваемую нумерацией версий, намного лучше.
Я запустил его с помощью этого сообщения SO: Gradle, Android, Jacoco и JUnit5, но требует, чтобы я выключилfailOnVersionConflict
Когда я включаю его, я получаю конфликт версий в apiguardian-api между 1.0.0 и 1.1.0. Выполнение сканирования дает следующий результат:
Dependency resolution failed because of conflict(s) on the following module(s):
- org.apiguardian:apiguardian-api between versions 1.1.0 and 1.0.0
org.apiguardian:apiguardian-api:1.1.0
variant "runtime" [
org.gradle.status = release (not requested)
org.gradle.usage = java-runtime (not requested)
org.gradle.libraryelements = jar (not requested)
org.gradle.category = library (not requested)
]
Selection reasons:
- By conflict resolution : between versions 1.1.0 and 1.0.0
org.apiguardian:apiguardian-api:1.1.0
+--- org.junit.platform:junit-platform-commons:1.5.2
| \--- org.junit.platform:junit-platform-engine:1.5.2
| \--- org.junit.platform:junit-platform-launcher:1.0.0 (requested org.junit.platform:junit-platform-engine:1.0.0)
| +--- junitPlatform
| \--- org.junit.platform:junit-platform-console:1.0.0
| \--- junitPlatform
\--- org.junit.platform:junit-platform-engine:1.5.2 (*)
org.apiguardian:apiguardian-api:1.0.0 -> 1.1.0
+--- org.junit.platform:junit-platform-console:1.0.0
| \--- junitPlatform
\--- org.junit.platform:junit-platform-launcher:1.0.0
+--- junitPlatform
\--- org.junit.platform:junit-platform-console:1.0.0 (*)
(*) - dependencies omitted (listed previously)
Выполнение --scan и некоторый анализ показывают, что проблема, я думаю, в junitPlatform. Итак, я хочу явно исключить apiguardian-api 1.0.0 из моих зависимостей или принудительно использовать 1.1.0, но я не могу найти, где определена зависимость и где ее исключить.
Я пробовал следующее, но без особого успеха: - явно добавить зависимость в упомянутые библиотеки junit-platform с самыми последними версиями - иметь зависимость от последней версии junit-bom - определить разрешение Strategy, которое разрешает apiguardian-api как 1.1.0 версия.
Что бы я ни делал, я не могу заставить Gradle отказаться от версии 1.0.0 в пользу версии 1.1.0.
Кстати, я использую Spring Boot 2.2.2-RELEASE в качестве основы своего проекта и Jacoco 0.85
Кроме того, в качестве FYI, что может быть виновником, я использую junit-platform-gradle-plugin 1.0.0, чтобы заставить jacoco работать. Я бы предпочел не использовать его, потому что он устарел, но я не мог заставить jacoco работать иначе. Он определяется как зависимость в верхней части моего файла build.gradle в блоке buildscript, я исключил apiguardian из этой зависимости следующим образом:
buildscript {
ext {
springBootVersion = '2.2.2.RELEASE'
jUnitVersion = '5.5.2'
}
repositories {
mavenCentral()
jcenter() // for gradle-versions-plugin
}
dependencies {
// https://mvnrepository.com/artifact/org.junit/junit-bom
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath ('org.junit.platform:junit-platform-gradle-plugin:1.0.0') {
exclude group: "or.apiguardian", module: "apiguardian-api"
}
}
}
Без использования этого плагина gradle, который, как я знаю, помечен как устаревший, поскольку Gradle изначально поддерживает junit 5. Без него я вообще не могу заставить jacoco генерировать какие-либо отчеты.
Надеюсь, кто-нибудь сможет мне помочь, заранее спасибо.
build.gradle:
buildscript {
ext {
springBootVersion = '2.2.2.RELEASE'
jUnitVersion = '5.5.2'
}
repositories {
mavenCentral()
jcenter() // for gradle-versions-plugin
}
dependencies {
// https://mvnrepository.com/artifact/org.junit/junit-bom
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath ('org.junit.platform:junit-platform-gradle-plugin:1.0.0') {
exclude group: "org.apiguardian", module: "apiguardian-api"
}
}
}
plugins {
id 'java'
id 'idea'
id "org.sonarqube" version "2.8"
id 'io.franzbecker.gradle-lombok' version '3.2.0' apply false
id "io.spring.dependency-management" version "1.0.8.RELEASE" apply false
id "com.github.spacialcircumstances.gradle-cucumber-reporting" version "0.1.15" apply false
id 'org.asciidoctor.convert' version '2.4.0' apply false
id "com.github.ben-manes.versions" version "0.27.0"
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
apply plugin: 'idea'
group = 'io.criticalpathomizer.cpmodel'
version = project.majorMinorBugfix + '-' + project.buildNumber
ext['junit-jupiter.version'] = '5.5.2' // Also change jUnitVersion
ext {
// SPRING
springBootVersion = '2.2.2.RELEASE'
springRestDocsVersion = '2.0.4.RELEASE'
springHalBrowserVersion = "3.2.3.RELEASE"
springDocOpenApiCoreVersion = "1.2.26"
springDocOpenApiUIVersion = "1.2.26"
// UTILS
lombokVersion = '1.18.10'
slf4jVersion = '1.7.29'
logBackClassicVersion = '1.2.3'
jerseyClientVersion = "2.30"
apacheHttpClientVersion = "4.5.10"
// TESTING
mockitoCoreVersion = '3.2.4'
jUnitVersion = '5.5.2'
jUnitPlatformVersion = '1.5.2'
cucumberVersion = '4.8.0'
cucumberReportingVersion = '5.0.1'
hamcrestVersion = "1.3"
// DATABASE
rdfVersion = "3.0.2"
hsqlVersion = "2.5.0"
h2databaseVersion="1.4.200"
// DEFAULT
guavaVersion = "28.2-jre"
apacheCommonsMathVersion = "3.6.1"
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: "io.franzbecker.gradle-lombok"
apply plugin: 'org.asciidoctor.convert'
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
testCompile group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.5.2'
api group: 'org.apache.commons', name: 'commons-math3', version: "${apacheCommonsMathVersion}"
implementation group: 'com.google.guava', name: 'guava', version: "${guavaVersion}"
compileOnly group: 'org.projectlombok', name: 'lombok', version: "${lombokVersion}"
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
configure(subprojects.findAll { it.name != 'docs' && it.name != 'service.api' }) {
// -----------------------------------------------------------
//
// Jacoco
//
apply plugin: 'jacoco'
apply plugin: 'org.junit.platform.gradle.plugin'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.jacoco:org.jacoco.agent:0.8.5:runtime'
}
jacoco {
toolVersion = "0.8.5"
applyTo junitPlatformTest
}
jacocoTestReport {
reports {
xml.enabled true
csv.enabled false
html.enabled = true
html.destination file("${buildDir}/reports/jacoco/jacocoHtml")
}
}
ext {
minCodeCoverage = 45
}
junitPlatformTest {
jacoco {
destinationFile = file("$buildDir/jacoco/test.exec")
}
}
}
task jacocoRootReport(type: JacocoReport) {
dependsOn = subprojects.test
getAdditionalSourceDirs().setFrom(files(subprojects.sourceSets.main.allSource.srcDirs))
getSourceDirectories().setFrom(files(subprojects.sourceSets.main.allSource.srcDirs))
getClassDirectories().setFrom(files(subprojects.sourceSets.main.output))
getExecutionData().setFrom(files(subprojects.jacocoTestReport.executionData))
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
onlyIf = {
true
}
doFirst {
getExecutionData().setFrom(files(executionData.findAll {
it.exists()
}))
}
}
configure(subprojects.findAll { it.name != 'docs' }) {
// -----------------------------------------------------------
//
// Spring
//
apply plugin: 'io.spring.dependency-management'
dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter', version: "${springBootVersion}"
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: "${springBootVersion}"
}
dependencyManagement {
imports { mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}") }
}
// -----------------------------------------------------------
//
// jUnit
//
dependencies {
implementation group: "org.junit", name:"junit-bom", version:"${jUnitVersion}"
testCompile group: 'org.junit.platform', name: 'junit-platform-console', version: "${jUnitPlatformVersion}"
testCompile group: 'org.junit.platform', name: 'junit-platform-launcher', version: "${jUnitPlatformVersion}"
compile group: 'org.junit.platform', name: 'junit-platform-commons', version: "${jUnitPlatformVersion}"
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: "${jUnitVersion}"
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: "${jUnitVersion}"
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "${jUnitVersion}"
testRuntimeOnly group: 'org.junit.vintage', name: 'junit-vintage-engine', version: "${jUnitVersion}"
}
// -----------------------------------------------------------
//
// Cucumber
//
dependencies {
// Use annotations to define cucumber.steps
testImplementation group: "io.cucumber", name: "cucumber-java", version: "${cucumberVersion}"
testImplementation group: "io.cucumber", name: "cucumber-junit", version: "${cucumberVersion}"
testImplementation group: "io.cucumber", name: "cucumber-spring", version: "${cucumberVersion}"
implementation ("net.masterthought:cucumber-reporting:${cucumberReportingVersion}") {
exclude group: "commons-logging", module: "commons-logging"
}
}
}
wrapper {
gradleVersion = '6.0.1'
}
: application: build.gradle
import java.text.SimpleDateFormat
plugins {
id 'org.springframework.boot'
id "com.github.spacialcircumstances.gradle-cucumber-reporting"
id 'org.asciidoctor.convert'
}
apply plugin: 'org.springframework.boot'
// -----------------------------------------------------------
group = 'io.criticalpathomizer.cpmodel'
description = 'Project Module - Application'
version = '0.0.1-SNAPSHOT'
bootJar {
dependsOn asciidoctor
mainClassName = 'io.criticalpathomizer.cpm.ModelApplication'
from ("${asciidoctor.outputDir}/html5") {
into 'static/docs'
}
}
dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: "${springBootVersion}"
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-hateoas', version: "${springBootVersion}"
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: "${springBootVersion}"
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: "${springBootVersion}"
implementation ("org.springdoc:springdoc-openapi-webmvc-core:${springDocOpenApiCoreVersion}") {
exclude group: "io.github.classgraph", module: "classgraph"
}
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: "${springDocOpenApiUIVersion}"
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: "${apacheHttpClientVersion}"
}
// -----------------------------------------------------------
//
// jUnit
//
dependencies {
testImplementation group: 'org.springframework.restdocs', name: 'spring-restdocs-mockmvc', version: "${springRestDocsVersion}"
}
test {
useJUnitPlatform ()
testLogging {
events "passed", "skipped", "failed"
}
reports {
junitXml.enabled = true
html.enabled = true
}
testLogging.showStandardStreams = true
systemProperties System.getProperties()
finalizedBy jacocoTestReport
}
// -----------------------------------------------------------
//
// Cucumber
//
dependencies {
implementation project (':model')
implementation project (':repository')
implementation project (':service.api')
implementation group: 'org.glassfish.jersey.core', name: 'jersey-client', version: "${jerseyClientVersion}"
}
cucumberReports {
outputDir = file("$projectDir/build/reports/tests")
buildId = '0'
reports = files('target/cucumber-reports/models/Cucumber.json', 'target/cucumber-reports/version/Cucumber.json')
}
// -----------------------------------------------------------
dependencies {
implementation project (':model')
implementation project (':repository')
implementation project (':service.api')
implementation project (':service.impl')
}
// -----------------------------------------------------------
//
// ASCII Doctor
dependencies {
implementation group: 'org.springframework.restdocs', name: 'spring-restdocs-asciidoctor', version: "${springRestDocsVersion}"
testImplementation group: 'org.springframework.restdocs', name: 'spring-restdocs-mockmvc', version: "${springRestDocsVersion}"
}
ext {
snippetsDir = file('build/generated-snippets')
}
test {
outputs.dir snippetsDir
}
asciidoctor {
attributes "snippets": snippetsDir,
"source-highlighter": "coderay",
"version": version,
"date": new SimpleDateFormat("yyyy-MM-dd").format(new Date()),
"stylesheet": "themes/riak.css"
inputs.dir snippetsDir
dependsOn test
outputDir "build/docs"
}
build.dependsOn asciidoctor