m52509791
m52509791

Reputation: 467

Maven and spring-boot-dependencies

I have a Maven multimodule project that has some old version of spring-boot-dependencies set as parent in the main pom.xml. All submodules inherit spring boot dependencies from this main pom.xml.

And this is fine but in one of the new submodule (being also multi module) I want to use the newest spring boot version without changing the one that is being used (together with all the dependencies) across the project.

Is there a way to cleverly override the version of spring boot (with all its dependencies) derived from parent and use different one in submodule? I tried to setup explicit version of spring boot within <spring-boot.version> property in all new module's submodules' pom.xml files but without luck.

Upvotes: 4

Views: 5878

Answers (1)

Andy Wilkinson
Andy Wilkinson

Reputation: 116041

Is there a way to cleverly override the version of spring boot (with all its dependencies) derived from parent and use different one in submodule?

No. When you use a specific version of Spring Boot as the parent (or grandparent, etc), you're saying that's the version of Spring Boot that you want to use.

I tried to setup explicit version of spring boot within property in all new module's submodules' pom.xml files but without luck.

If this did work you'd end up with the parent from Spring Boot version X with configuration such as the Maven plugin management for that version alongside dependencies from Spring Boot version Y. This mixture of versions could lead to strange and unexpected behaviour that would be very hard to diagnose.

If you want to be able to mix and match versions like this, you should avoid using the parent from Spring Boot and should import spring-boot-dependencies instead:

<dependencyManagement>
    <dependencies>
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.3.2.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

This gives you complete control over the version at the cost of having to define any plugin management that you need yourself. It's also worth noting that you can't override properties from an imported pom.

Upvotes: 6

Related Questions