I am trying to use maven BOM with gradle 5.1.1 as mentioned below
ext {
set('spring-boot-dependencies.version', '2.1.2.RELEASE')
}
apply plugin: 'java'
group 'com.acme'
version '1.0.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
dependencies {
// maven bom
implementation platform("org.springframework.boot:spring-boot-dependencies:${project.'spring-boot-dependencies.version'}")
compileOnly('org.projectlombok:lombok')
annotationProcessor('org.projectlombok:lombok')
}
When I run ./gradlew dependencies --configuration=annotationProcessor
& ./gradlew dependencies --configuration=compileOnly
, I get the following respectively
annotationProcessor - Annotation processors and their dependencies for source set 'main'.
\--- org.projectlombok:lombok FAILED
compileOnly - Compile only dependencies for source set 'main'.
+--- org.projectlombok:lombok FAILED
Strangely, IntelliJ resolves compileOnly
dependencies properly, but not annotationProcessor
I am quite confused as to what is going on. Any help is appreciated
In Gradle, a platform, like regular dependencies, is scoped to a given configuration (and the configurations extending it).
In your example, the BOM is only used in implementation
and thus will only provide recommendations for that configuration and the ones extending it, like compileClasspath
or runtimeClasspath
.
In order to solve your issue, you will need to declare the BOM to all the configurations where you want to benefit from its recommended versions.
You can achieve this by repeating the declaration:
compileOnly platform("org.springframework.boot:spring-boot-dependencies:${project.'spring-boot-dependencies.version'}")
annotationProcessor platform("org.springframework.boot:spring-boot-dependencies:${project.'spring-boot-dependencies.version'}")
or you could create a dedicated configuration and make all the configurations requiring constraints extend it:
configurations {
springBom
compileOnly.extendsFrom(springBom)
annotationProcessor.extendsFrom(springBom)
implementation.extendsFrom(springBom)
}
dependencies {
springBom platform("org.springframework.boot:spring-boot-dependencies:${project.'spring-boot-dependencies.version'}")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With