Maven-在存储库中安装时替换project.pom文件中的属性 [英] Maven - Replace property in project.pom file when installing in repository

查看:94
本文介绍了Maven-在存储库中安装时替换project.pom文件中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个定义属性的父项目,例如:

I have a parent project that defines a property, for example:

    <properties>
        <myproject-version>1.0</myproject-version>
    </properties>

我在一个儿童"项目中使用

In a 'child' project I use

<parent>
    <groupId>com.home</groupId>
    <artifactId>my-modules</artifactId>
    <version>${myproject-version}</version>
</parent>

一切正常,但是当Maven在存储库中安装jar时,它会创建类似pom的

Everything works nice, but when Maven installs jar in repository, it creates pom like

<parent>
    <groupId>com.home</groupId>
    <artifactId>my-modules</artifactId>
    <version>${myproject-version}</version>
</parent>

我需要将my-version的值替换为1.0

And I need that value of my-version to be replaced with 1.0

<parent>
    <groupId>com.home</groupId>
    <artifactId>my-modules</artifactId>
    <version>1.0</version>
</parent>

有没有办法做到这一点?我需要1.0,因为其他项目将我的项目用作依赖项时会发生一些编译问题. (他们寻找的是$ {myproject-version}版本而不是'1.0'

Is there any way to do that? I need 1.0 because of some compilation problems that occure when other projects use my project as dependency. (They look for a version ${myproject-version} instead of '1.0'

推荐答案

实际上,我很惊讶地看到它甚至可以正常工作.必须在父标记中指定版本 (否则无法知道要从存储库中提取哪个版本),但是该版本不应该根据数据进行定义在父pom中定义,否则会出现一个明显的问题:需要使用父pom来确定需要哪个父pom.

Actually, I'm surprised to see this even working. A version must be specified in the parent tag (otherwise there is no way to know which version to pull from the repository) but that version should not be defined in terms of data defined in the parent pom, otherwise an obvious problem occurs: the parent pom would be needed to determine which parent pom is needed.

因此,我认为没有任何方法可以做您想做的事情,老实说,我认为这是个坏主意.

So I don't think there is any way to do what you are trying to do and, to be honest, I think its a bad idea.

这篇关于Maven-在存储库中安装时替换project.pom文件中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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