Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to use Maven BOM in gradle 5 with annotationProcessor configuration

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

intellij gradle view

like image 840
Ashok Koyi Avatar asked Feb 04 '19 21:02

Ashok Koyi


1 Answers

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'}")
}
like image 107
Louis Jacomet Avatar answered Sep 20 '22 04:09

Louis Jacomet