通过属性文件指定pom属性? [英] Specify pom properties via a properties file?

查看:48
本文介绍了通过属性文件指定pom属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我的构建系统的设计方式(RTC Build Engine),我想通过属性文件为Maven提供属性值,而不是为每个属性指定-Dkey = value.

我在S.O上发现了几个问题.(如何从Maven POM中的文件设置构建属性?解决方案

在pom中,您可以放置​​...

 < properties>< core-version> 1234</core-version>< lib-version> 1234</lib-version>< build-version> 9999</lib-version>< build-date> 20150101</build-date></properties> 

具有您需要的所有属性.

或者您可以使用...

 < build>< plugins>< plugin>< groupId> org.codehaus.mojo</groupId>< artifactId> properties-maven-plugin</artifactId>< version> 1.0-alpha-2</version><执行><执行><相位>初始化</phase><目标>< goal>读取项目属性</goal></goals><配置><文件>< file> dev.properties</file></files></configuration></execution></executions></plugin></plugins></build> 

和文件 dev.properties 将包含属性

  core-version = 1234lib-version = 1234build-version = 9999建立日期= 20150101... 

或者...您可以使用settings.xml文件注入属性,如此处

Due to the way my build system is designed (RTC Build Engine), I would like to provide maven with property values via a properties file, instead of specifying -Dkey=value for every property.

I found a couple of questions on S.O. (How to set build properties from a file in Maven POM? and How to read an external properties file in Maven) that relate precisely to this question, but they are relatively old, and both require custom plugins to work (in alpha state).

I realize that passing parameters to Maven like this is probably not the best solution, but the other option is specifying everything on the command line via -D settings which is not ideal either.

Furthermore, given that this properties file is only really used by the build engine (and not by the individual developer), I don't truly believe it belongs in the pom. But I cannot find any other mechanism that would allow me to specify a plugin to use - settings.xml does not permit specifying plugins.

Is my only choice in this case to use a plugin and specify it in the project pom?

解决方案

in the pom you can place...

<properties>
    <core-version>1234</core-version>
    <lib-version>1234</lib-version>
    <build-version>9999</lib-version>
    <build-date>20150101</build-date>
</properties>

with all the properties you require.

Or you can use...

<build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0-alpha-2</version>
        <executions>
          <execution>
            <phase>initialize</phase>
            <goals>
              <goal>read-project-properties</goal>
            </goals>
            <configuration>
              <files>
                <file>dev.properties</file>
              </files>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

and the file dev.properties will contain the properties

core-version=1234
lib-version=1234
build-version=9999
build-date=20150101
...

Or... you can inject the properties using a settings.xml file as shown here

You may also find the Maven build number plugin useful... here

这篇关于通过属性文件指定pom属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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