mavenmaven-enforcer-plugin

Maven enforcer plugin is not enforcing


In pom I have parameter for one of the artifact id:

    <dependency>
      <groupId>com.abc.automation</groupId>
      <artifactId>${app}-xyz-extension</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <type>test-jar</type>
    </dependency>

I intend to enforce any one using this pom to pass the param -Dapp ; for this I am using the enforcer plugin:

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-enforcer-plugin</artifactId>
          <version>3.0.0-M3</version>
          <executions>
            <execution>
              <id>enforce-property</id>
              <phase>validate</phase>
              <goals>
                <goal>enforce</goal>
              </goals>
              <configuration>
                <rules>
                  <requireProperty>
                    <property>app</property>
                    <message>
                      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                      You must set the app property!
                      This is used to determine which app is being tested and load the
                      corresponding extension.
                      Example: -Dapp=sampeapp
                      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    </message>
                    <!--<regex>.*\d.*</regex>-->
                  </requireProperty>
                </rules>
                <fail>true</fail>
              </configuration>
            </execution>
          </executions>
        </plugin>

However this is not enforcing that the -Dapp needs to be base instead what i get is error from pom that

[ERROR] The build could not read 1 project -> [Help 1] org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs: [ERROR] 'dependencies.dependency.artifactId' for com.abc.automation:${app}-xyz-extension:test-jar with value '${app}-taas-extension' does not match a valid id pattern. @ line 18, column 19

Plugins element is placed inside build as below:

<build>
<pluginManagement>
  <plugins>
    <plugin>
         ....
    </plugin>
  </plugins>
</pluginManagement>
</build>

Am i missing the basics of enforcer plugin?


Solution

  • Deepak, it may be because of some other plugin/dependency that has placeholder ${app} written before enforce plugin.