Skip to content
Advertisement

Define Spring dependency matching a Spring Boot version

I am developing two projects.

Project 1 is a spring-boot application based on gradle for dependency management. This application defines extension-points. If – at runtime – an extension is found on the classpath, this extension is being called from the main application under certain circumstances.

Project 2 is such an extension. This extension should only provide low-level functionality. So basically, I need spring annotations and an EntityManager within the application but I would like to prevent the full spring-boot dependencies to be present on the compile-path.

The obvious (and not satisfactory) solution is to define a compileonly-dependency on a specific version of, say, spring-context. This is somewhat dangerous, as the spring-boot version may progress and it may be easy to forget to adjust the spring version.

Providing a compileOnly dependency to spring-boot-starter (or even the main project) is out of the question.

So, is there a clever trick to tell gralde to use “the spring-version coming with spring-boot-xxx”?

Advertisement

Answer

Sometimes you are within a forrest and not seeing the trees…

Thanks to the comment of @emrekgn I looked for BOM/Gradle/Spring and found… the spring boot dependency-management plugin.

Adding this to your gradle file will allow you to include dependencies matching to the spring boot version you are using:

plugins {
    id 'org.springframework.boot' version '2.6.2'
}

apply plugin: 'io.spring.dependency-management'

Obviously, you have to match the boot-version to your needs.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement