【问题标题】:Custom values in Maven pom.properties fileMaven pom.properties 文件中的自定义值
【发布时间】:2012-04-23 13:46:20
【问题描述】:

我正在尝试在 Maven 在 META-INF/maven/${groupId}/${artifactId} 位置生成的 pom.properties 文件中添加自定义值

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.4</version>
    <configuration>
            <archive>
                <manifestEntries>
                    <build>${BUILD_TAG}</build>
                </manifestEntries>
                <addMavenDescriptor>true</addMavenDescriptor>
                <pomPropertiesFile>${project.build.directory}\interface.properties</pomPropertiesFile>
            </archive>
    </configuration>
</plugin>

interface.properties文件的内容是

# Build Properties
buildId=746

使用documentation我已经将pomPropertiesFile元素指向一个外部属性,但是运行mvn install后生成的pom.properties文件仍然有默认内容

pomPropertiesFile 元素的正确用法是什么?

编辑

我认为问题出在 org.apache.maven.archiver.PomPropertiesUtil 上。如果您查看source 中的方法sameContents,如果外部文件中的属性与默认值相同,则返回true,如果不同,则返回false。如果sameContents 的结果为假,则忽略外部文件的内容。

果然,这已经是logged的bug了

【问题讨论】:

  • interface.properties 长什么样子?
  • 这是一个标准的属性文件。
  • 不要在 Maven pom 中使用“\”。请改用“/”。
  • 不要将答案添加到问题本身。在 StackOverflow 上被认为是不好的做法。相反,请在页面末尾按Answer Your Question 并将您的答案放在那里。

标签: maven maven-3 pom.xml


【解决方案1】:

我认为您需要在 src/main/resources/META-INF/${groupId}/${artifactId}/interface.properties 下放置一个文件,然后让 maven 完成过滤工作(配置过滤)。该文件将自动复制到 target/META-INF/maven/${groupId}/${artifactId}/ 位置。

【讨论】:

  • 这个文件是在构建过程中动态生成的,所以我不认为把它放在源代码树中是个好习惯。
【解决方案2】:

https://issues.apache.org/jira/browse/MNG-4998

Maven 3 将在读取 pom.xml 以获取此时可用的所有属性值时急切地解析属性占位符。以后修改这些属性不会影响 pom.xml 中已经解析的值。

但是,如果属性值不可用(没有默认值),则占位符不会被该值替换,并且以后仍然可以作为占位符处理。例如,如果插件将在构建期间生成某些属性,或者如果插件在某些构建步骤中读取和处理占位符。

【讨论】:

    猜你喜欢
    • 2019-08-17
    • 2016-09-07
    • 1970-01-01
    • 2015-05-05
    • 2011-03-30
    • 2012-08-19
    • 2010-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多