How can I override maven property values set by properties-maven-plugin's read-project-properties goal?

admin

Administrator
Staff member
In one of our projects, we use the properties-maven-plugin's read-project-properties goal to read property values from a file which are then used for filtering resources. See <a href="https://stackoverflow.com/questions...es-maven-plugin-and-filter-in-a-maven-profile">this post</a> for a discussion on the general purpose of this procedure.

We would like to override some of the values found in the file using a suitable profile defined in the developer specific settings.xml (the same way we override properties set in the POM).

This, however, does not work for the properties set by the properties-maven-plugin.

How can we achieve our goal?

As a work around, we are currently registering an additional, developer specific file with the properties-maven-plugin to achieve this effect but it would be much more convenient to use the regular way (profiles).

In more general terms, the question is: How do properties set by properties-maven-plugin's read-project-properties goal tie into the property definition precedence hierarchy of maven, which is described in this <a href="https://davidmarquis.wordpress.com/2011/01/13/maven-custom-properties-precedence/" rel="nofollow noreferrer">very helpful blog post</a>.

I extracted the relevant elements of our POM into a toy project that demonstrates my issue. Here is the POM of the toy project:

Code:
&lt;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"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;xxx&lt;/groupId&gt;
  &lt;artifactId&gt;MavenTest&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;Maven Test&lt;/name&gt;
  &lt;description&gt;A maven project to test filtering and the maven-properties-plugin&lt;/description&gt;
  &lt;build&gt;
    &lt;resources&gt;
      &lt;resource&gt;
        &lt;directory&gt;src/main/resources&lt;/directory&gt;
        &lt;filtering&gt;true&lt;/filtering&gt;
      &lt;/resource&gt;
    &lt;/resources&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
        &lt;artifactId&gt;properties-maven-plugin&lt;/artifactId&gt;
        &lt;executions&gt;
          &lt;!-- Read properties from a file --&gt;
          &lt;execution&gt;
            &lt;id&gt;load-filter-properties&lt;/id&gt;
            &lt;goals&gt;
              &lt;goal&gt;read-project-properties&lt;/goal&gt;
            &lt;/goals&gt;
            &lt;phase&gt;initialize&lt;/phase&gt;
            &lt;configuration&gt;
              &lt;files&gt;
                &lt;file&gt;filters/filterTest.properties&lt;/file&gt;
              &lt;/files&gt;
              &lt;quiet&gt;false&lt;/quiet&gt;
            &lt;/configuration&gt;
          &lt;/execution&gt;
          &lt;!-- The following execution is for debug purposes only --&gt;
          &lt;execution&gt;
            &lt;id&gt;write-project-properties&lt;/id&gt;
            &lt;inherited&gt;false&lt;/inherited&gt;
            &lt;goals&gt;
              &lt;goal&gt;write-project-properties&lt;/goal&gt;
            &lt;/goals&gt;
            &lt;phase&gt;package&lt;/phase&gt;
            &lt;configuration&gt;
              &lt;outputFile&gt;filters/project.properties&lt;/outputFile&gt;
            &lt;/configuration&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;junit&lt;/groupId&gt;
      &lt;artifactId&gt;junit&lt;/artifactId&gt;
      &lt;version&gt;4.12-beta-1&lt;/version&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;
&lt;/project&gt;