使用依赖项管理访问Maven属性 [英] Access maven property using dependency management

查看:91
本文介绍了使用依赖项管理访问Maven属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用maven的依赖项管理将POM导入到我的项目Y中,如下所示:

I am using maven's dependency-management to import the POM into my project Y as below:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.abc</groupId>
            <artifactId>X</artifactId>
            <version>1.0</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

我的工件X具有要在项目Y的POM中访问的以下属性:

And my artifact X has following properties which I want to access in POM of project Y:

<properties>
    <property1>value1</property1>
    <property2>value2</property2>
</properties>

我无法将X中定义的属性访问到Project Y中.我了解使用上述方法无法使用插件管理,但是无法找到与Web上的属性相关的任何内容.

I am not able to access properties defined in X into Project Y. I understand that using above approach I can't make use of plugin-management but I was unable to find anything related to properties on web.

另外请注意,由于我们已经定义了项目级别的父级,因此我不能将工件X用作父级.

Also please note I can't use the artifact X as parent as we have project level parent already defined.

请您指导一下.

推荐答案

如果将其声明为父级,则只能从另一个pom继承属性.导入import类型的pom仅导入其依赖项,如

You can only inherit properties from another pom, if you declare that as a parent. Importing a pom with type import only imports its dependencies, as described in the documentation. Since using the other pom as a parent is not possible in your case, let me suggest an alternative:

codehaus 属性Maven插件可以从外部文件.它甚至可以使用classpath: URL从中加载文件.因此,您可以尝试从另一个依赖项加载它们(应该具有适当的scope,因为您可能不希望该依赖项的JAR在运行时徘徊).

The codehaus Properties Maven Plugin can load maven properties from an external file. It can even use classpath: URLs to load files from. So you might try to load those from another dependency (which should have an appropriate scope since you probably do not want that dependency's JAR to hang around at runtime).

这篇关于使用依赖项管理访问Maven属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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