在maven和maven插件中选择依赖关系版本 [英] Choosing dependency version in maven and maven plugin

查看:206
本文介绍了在maven和maven插件中选择依赖关系版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用hsqldb 1.8.0.10的maven插件。在我的插件的pom.xml中,它被声明为:

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

但是,如果我从另一个maven项目运行该插件,并且该项目具有较新版本的hsqldb例如1.9.0),如何配置我的插件,他将使用最新版本的hsqldb,而不改变它的pom.xml?



是否可以这样做相反呢?如果我的其他maven项目使用hsqldb 1.7.0(例如),他将使用maven插件本身指定的1.8.0.10版本?



我希望有人可以回答我的问题。



请问,



Walle

解决方案

您的主要问题是可能的,但如果插件因为任何原因不适用于较新的代码,则可能无法正常工作。



插件可以拥有自己的个人依赖关系部分,并使用标准的Maven依赖关系分辨率,选择要求的最高版本。所以,你可以做

 < plugin> 
< groupId> some.group.id< / groupId>
< artifactId> some.artifact.id< / artifactId>
< version> someversion< / version>
<依赖关系>
<依赖关系>
< groupId> hsqldb< / groupId>
< artifactId> hsqldb< / artifactId>
< version> 1.9.0< / version>
< / dependency>
< / dependencies>
< / 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

解决方案

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.

这篇关于在maven和maven插件中选择依赖关系版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆