Maven是否有办法获得依赖版本的属性? [英] Does Maven have a way to get a dependency version as a property?

查看:193
本文介绍了Maven是否有办法获得依赖版本的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用BOM表从另一个项目中导入依赖关系来挖掘我的依赖关系,并且我需要一种方法来引用已在所述BOM表中声明的依赖关系版本.到目前为止,我已经尝试将依赖项版本作为BOM中的属性列出,但是这种方法失败了,因为属性没有随BOM一起导入.

I'm using a BOM to import dependencies from another project to mine, and I need a way to reference a dependency's version that is already declared in said BOM. So far, I've attempted to list the dependency version as a property in the BOM, but this approach fails because properties don't get imported with BOMs.

我已经看到了依赖插件的 dependency:properties 目标确实完全满足了我的需求,但我没有为工件提供完整的路径,而是需要将版本作为属性.有没有什么可以让我将已解析工件的版本作为属性的?

I've seen where the Dependency Plugin's dependency:properties goal does almost exactly what I need, but instead of giving me a full path of the artifact I need the version as a property. Is there something out there that can give me the version of a resolved artifact as a property?

更新-'为什么不使用父pom?'

我通常发现自己在应用程序服务器环境中工作,在该环境中,提供的依赖项是通过BOM工件指定的(因为看来这已成为分发相互关联的工件组的某种通用/标准方式,即 widlfly ).因此,我想将BOM作为真实的唯一来源.做类似 re-delcaring 依赖项属性(已经在BOM表中定义)之类的想法似乎是错误的.

I commonly find myself working in application server environments, where the dependencies provided are specified with BOM artifacts (as it appears that this has become a somewhat common/standard way to distribute groups of inter-related artifacts, i.e. widlfly). As such, I want to treat the BOM as the single source of truth. The idea of doing something like re-delcaring a dependency version property that has already been defined in a BOM seems incorrect.

如果要在镜像应用程序服务器环境的父pom中定义属性,那么我现在不得不担心保持父pom属性和BOM属性同步-为什么此时甚至要拥有BOM?

If I were to define properties in a parent pom that mirrored an application server's environment, I now have to worry about keeping parent pom properties and BOM properties in sync - why even have a BOM at all at that point?

信息已经在依赖树上可用,这只是暴露它的问题...

The information is already available on the dependency tree, it's just a matter of exposing it...

推荐答案

为此无法找到任何现有的maven或插件功能,因此我分叉了旧的dependencypath-maven-plugin并将其更改为使用版本.现在,我可以插入这样的插件:

Couldn't find any existing maven or plugin functionality for this, so I forked the old dependencypath-maven-plugin and altered it to use versions. Now I can drop in a plugin like this:

<build>
   .
   .
    <plugins>
        .
        .
        <plugin>
            <groupId>io.reformanda.semper</groupId>
            <artifactId>dependencyversion-maven-plugin</artifactId>
            <version>1.0.0</version>
            <executions>
                <execution>
                    <id>set-all</id>
                    <goals>
                        <goal>set-version</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

并访问如下属性:

groupId:artifactId:type [:classifier] .version

groupId:artifactId:type[:classifier].version

I.E.

io.undertow:undertow-core:jar.version = 1.3.15.Final

io.undertow:undertow-core:jar.version=1.3.15.Final

查看自述文件以了解更多信息有关如何使用插件的信息.它可以在 Maven Central 中使用:

Check out the README for more info on how to use the plugin. It's available @ Maven Central:

<dependency>
    <groupId>io.reformanda.semper</groupId>
    <artifactId>dependencyversion-maven-plugin</artifactId>
    <version>1.0.0</version>
</dependency>

...插件一直到...

... plugins all the way down ...

这篇关于Maven是否有办法获得依赖版本的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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