From a9687ca5c78ad0f06ebaa58bb0f1c50c800550dc Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 16 Aug 2024 12:23:47 -0400 Subject: [PATCH] Revert back to registerFeature('optional') With a `components.java.addVariantsFromConfiguration(configurations.optional)` and `io.spring.dependency-management` combination the version is not published for `optional` dependencies. Does not look like there is an easy way to extract that version somehow. So, revert back to the `registerFeature('optional')` for time being. Even if it is reported as deprecated in Gradle (cherry picked from commit 54400b2ad6b1387c8e74f64d34e489afdd8be73d) # Conflicts: # build.gradle --- build.gradle | 59 +++++++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/build.gradle b/build.gradle index cc5312c47a..911cd02b79 100644 --- a/build.gradle +++ b/build.gradle @@ -131,25 +131,12 @@ configure(javaProjects) { subproject -> def scopeAttribute = Attribute.of('dependency.scope', String) - configurations { - optional { - attributes { - attribute(scopeAttribute, 'optional') - } - } - - compileClasspath.extendsFrom(optional) - testCompileClasspath.extendsFrom(optional) - testRuntimeClasspath.extendsFrom(optional) - } - - components.java.addVariantsFromConfiguration(configurations.optional) { - mapToOptional() - } - java { withJavadocJar() withSourcesJar() + registerFeature('optional') { + usingSourceSet(sourceSets.main) + } } compileJava { @@ -166,10 +153,6 @@ configure(javaProjects) { subproject -> // dependencies that are common across all java projects dependencies { - attributesSchema { - attribute(scopeAttribute) - } - implementation "com.google.code.findbugs:jsr305:$googleJsr305Version" testImplementation 'org.junit.jupiter:junit-jupiter-api' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' @@ -186,7 +169,7 @@ configure(javaProjects) { subproject -> exclude group: 'org.hamcrest' } testImplementation "org.hamcrest:hamcrest-core:$hamcrestVersion" - optional "org.assertj:assertj-core:$assertjVersion" + optionalApi "org.assertj:assertj-core:$assertjVersion" } // enable all compiler warnings; individual projects may customize further @@ -292,27 +275,27 @@ project ('spring-kafka') { exclude group: 'org.springframework' } api "org.apache.kafka:kafka-clients:$kafkaVersion" - optional "org.apache.kafka:kafka-streams:$kafkaVersion" - optional 'com.fasterxml.jackson.core:jackson-core' - optional 'com.fasterxml.jackson.core:jackson-databind' - optional 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8' - optional 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310' - optional 'com.fasterxml.jackson.datatype:jackson-datatype-joda' - optional ('com.fasterxml.jackson.module:jackson-module-kotlin') { + optionalApi "org.apache.kafka:kafka-streams:$kafkaVersion" + optionalApi 'com.fasterxml.jackson.core:jackson-core' + optionalApi 'com.fasterxml.jackson.core:jackson-databind' + optionalApi 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8' + optionalApi 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310' + optionalApi 'com.fasterxml.jackson.datatype:jackson-datatype-joda' + optionalApi ('com.fasterxml.jackson.module:jackson-module-kotlin') { exclude group: 'org.jetbrains.kotlin' } // Spring Data projection message binding support - optional ("org.springframework.data:spring-data-commons") { + optionalApi ("org.springframework.data:spring-data-commons") { exclude group: 'org.springframework' exclude group: 'io.micrometer' } - optional "com.jayway.jsonpath:json-path:$jaywayJsonPathVersion" + optionalApi "com.jayway.jsonpath:json-path:$jaywayJsonPathVersion" - optional 'io.projectreactor:reactor-core' - optional 'io.projectreactor.kafka:reactor-kafka' - optional 'io.micrometer:micrometer-core' - optional 'io.micrometer:micrometer-tracing' + optionalApi 'io.projectreactor:reactor-core' + optionalApi 'io.projectreactor.kafka:reactor-kafka' + optionalApi 'io.micrometer:micrometer-core' + optionalApi 'io.micrometer:micrometer-tracing' testImplementation project (':spring-kafka-test') testImplementation 'io.projectreactor:reactor-test' @@ -379,12 +362,12 @@ project ('spring-kafka-test') { } api 'org.junit.jupiter:junit-jupiter-api' api 'org.junit.platform:junit-platform-launcher' - optional "org.hamcrest:hamcrest-core:$hamcrestVersion" - optional "org.mockito:mockito-core:$mockitoVersion" - optional ("junit:junit:$junit4Version") { + optionalApi "org.hamcrest:hamcrest-core:$hamcrestVersion" + optionalApi "org.mockito:mockito-core:$mockitoVersion" + optionalApi ("junit:junit:$junit4Version") { exclude group: 'org.hamcrest', module: 'hamcrest-core' } - optional "org.apache.logging.log4j:log4j-core:$log4jVersion" + optionalApi "org.apache.logging.log4j:log4j-core:$log4jVersion" } }