Reputation: 31
I'm migrating a small multi-module project from Maven to Gradle, to evaluate and (hopefully) to learn something.
subprojects {
group = "com.company.project-name"
apply plugin: "java"
repositories {
mavenCentral()
}
dependencies {
implementation platform("org.springframework.boot:spring-boot-dependencies:2.5.2")
compileOnly("org.projectlombok:lombok")
annotationProcessor("org.projectlombok:lombok")
}
}
This is what I have so far. Despite a small problem it's already working. As you can see, I'm importing org.springframework.boot:spring-boot-dependencies
as platform dependency / BOM (Bill of Materials). As far as I understand this is equivalent to a Maven parent. spring-boot-dependencies
already defines almost everything I'm using in this project. However, I'm also using Lombok. Luckily Spring takes care of that too.
This work as expected for the compileOnly
dependency org.projectlombok:lombok
. The problem is the annotationProcessor
. Compiling the project results in an error:
[...]
Execution failed for task [...].
> Could not resolve all files for configuration [...].
> Could not find org.projectlombok:lombok:.
Required by:
project [...]
[...]
If I change it to something like this:
annotationProcessor("org.projectlombok:lombok:1.18.20")
... it works. But I want Gradle to use the version definition for Lombok from spring-boot-dependencies
, because I don't want to define it again myself. With Maven I could just use the Maven property lombok.version
. So I also tried something like this:
annotationProcessor("org.projectlombok:lombok:${lombok.version}")
Unfortunately, this result in another error:
A problem occurred evaluating root project [...].
> Could not get unknown property 'lombok' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
What is the Gradle equivalent to access a defined version property from a platform dependency / BOM?
Upvotes: 3
Views: 1175
Reputation: 43
Have you tried this:
annotationProcessor platform("org.springframework.boot:spring-boot-dependencies:2.5.2")
Make sure the annotationProcessor is on the top of the dependencies.
dependencies {
annotationProcessor platform("org.springframework.boot:spring-boot-dependencies:2.5.2")
annotationProcessor("org.projectlombok:lombok")
implementation platform("org.springframework.boot:spring-boot-dependencies:2.5.2")
compileOnly("org.projectlombok:lombok")
}
Upvotes: 2