Choosing dependency version in maven and maven plugin

社会主义新天地 提交于 2020-01-25 07:25:08

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/6030110/choosing-dependency-version-in-maven-and-maven-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!