read Maven variable from properties file using profile

社会主义新天地 提交于 2019-12-11 10:22:10

问题


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) made a profile (it works, can use mvn ... -P private)

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

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

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>

Thx a lot


回答1:


The name of your property is 'env' but you don't use env anywhere in your configuration.




回答2:


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.

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



来源:https://stackoverflow.com/questions/11600372/read-maven-variable-from-properties-file-using-profile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!