小编Ole*_*yuk的帖子

在将 pom 文件放入 maven 存储库之前,用 pom.xml 中的值替换属性

将项目安装到(本地)maven 存储库中时,我想用它们当前的实际值替换所有属性占位符,这有可能吗?

总而言之,我试图在 maven 中创建一个可自定义的项目版本,以解决传递依赖项的一些问题。

这是我最小化的 pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.foo</groupId>
<artifactId>T</artifactId>
<version>${custom.version}</version>

<properties>
    <custom.version>TEST</custom.version>
</properties>

<build>
    <resources>
        <resource>
            <directory>${basedir}</directory>
            <includes>
                <include>pom.xml</include>
            </includes>
            <filtering>true</filtering>
            <targetPath>${basedir}</targetPath>
        </resource>
    </resources>
</build>
Run Code Online (Sandbox Code Playgroud)

在“mvn clean install”之后,我想在本地maven存储库中拥有“~/.m2/repository/com/foo/T/TEST/T-Test.pom”以下内容:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.foo</groupId>
<artifactId>T</artifactId>
<version>TEST</version>

<properties>
    <custom.version>TEST</custom.version>
</properties>

<build>
    <resources>
        <resource>
            <directory>doesn't matter</directory>
            <includes>
                <include>pom.xml</include>
            </includes>
            <filtering>true</filtering>
            <targetPath>doesn't matter</targetPath>
        </resource>
    </resources>
</build>
Run Code Online (Sandbox Code Playgroud)

因此,在将项目安装到 maven 存储库之前,${custom.version} 占位符应替换为其当前值“TEST”。

但我得到的 - 是一个空文件,即使在当前项目目录中,可能是因为文件被锁定并且 maven 无法覆盖它。

是否有可能安装/部署具有解析属性值的 pom 文件?

pom.xml maven

5
推荐指数
1
解决办法
3967
查看次数

标签 统计

maven ×1

pom.xml ×1