使用配置文件从属性文件读取Maven变量 [英] read Maven variable from properties file using profile

查看:485
本文介绍了使用配置文件从属性文件读取Maven变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从属性文件中读取用于配置构建插件的maven变量.以及其他项目文件中都不需要它,例如上下文文件.

I want to read a maven variable for configure a build plugin from a properties file. It's not needed in and further project files e.g. context files.

1)制作了一个配置文件(它可以正常使用,可以使用mvn ... -P私有)

1) made a profile (it works, can use mvn ... -P private)

<profile>
 <id>private</id>
  <properties>
   <env>private</env>
  </properties>
</profile>

2)使用此内容创建了过滤器文件(有效) foo.path =/home/foo/path

2) created the filter file with this content (it works) foo.path=/home/foo/path

3)尝试配置插件(不起作用)

3) try to configure the plugin (does not work)

<build>
 <plugin>
   <groupId>org.codehaus.mojo</groupId>
    <artifactId>foo-plugin</artifactId>
    <version>${foo-plugin.version}</version>
    <configuration>
     <!--<fooPath>home/foo/path></fooPath> that works -->
     <fooPath>${foo.path}</fooPath> <!--works not -->
    </configuration>
...
</build>

非常感谢

推荐答案

当Maven文档提到过滤器文件"时,它们通常表示在处理资源(即将资源从/src/main/resources复制到target/classes)时使用的文件.据我所知,这些文件中的属性并未直接用于插件配置.我使用了Codehaus properties-maven-plugin:read -project-properties 目标可以完成您要尝试的工作.确保您将目标绑定到生命周期,然后再将所有需要配置属性的插件插入

When Maven docs mention "filter files" they usually mean a file used when processing resources (i.e. copying resources from /src/main/resources to target/classes). As far as I know the properties in those files aren't used for plugin configuration out-of-the-box. I have used the Codehaus properties-maven-plugin:read-project-properties goal do do what you are attempting. Make sure you bind the goal to the lifecycle before any plugins that need the properties for config.

此外,请参见此答案;您可以加载用于配置其他插件的属性,但不能加载用于配置Maven核心项目元素的属性.

Also, see this answer; you may load properties used to configure other plugins, but not to configure core Maven project elements.

这篇关于使用配置文件从属性文件读取Maven变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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