Walle
Walle

Reputation: 570

Choosing dependency version in maven and maven plugin

I have a maven plugin which is using hsqldb 1.8.0.10. In my pom.xml from the plugin, it is declared like this:

<dependency>
    <groupId>hsqldb</groupId>
    <artifactId>hsqldb</artifactId>
    <version>1.8.0.10</version>
</dependency>

But if I run that plugin from another maven project, and that project has a newer version of hsqldb (for instance 1.9.0), how can I configure my plugin that he will use the newest version of hsqldb, without changing it's pom.xml?

And is it possible to do this the other way around as well? If my other maven project uses hsqldb 1.7.0 (for instance), that he will use the 1.8.0.10 version which is specified in the maven plugin itself?

I hope someone can answer my question.

Kind regards,

Walle

Upvotes: 0

Views: 2512

Answers (2)

DuckPuppy
DuckPuppy

Reputation: 1366

Your main question is possible, but it might not work properly if the plugin doesn't work with the newer code for any reason.

A plugin can have it's own personal dependencies section, and will use standard Maven dependency resolution, choosing the highest version requested. So, you can do

<plugin>
    <groupId>some.group.id</groupId>
    <artifactId>some.artifact.id</artifactId>
    <version>someversion</version>
    <dependencies>
        <dependency>
            <groupId>hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <version>1.9.0</version>
        </dependency>
    </dependencies>
</plugin>

I don't think going the other way around is possible, though.

Upvotes: 1

user454043
user454043

Reputation:

use properties place holder for the version, say ${hsqldb.version} then declare in different project pom the version you want to put in it

Upvotes: 1

Related Questions