I'd like to use maven-tiles to configure plugins with a nailed down version as per (what I understood to be) the recommendations in the tiles-project. Since this is an extended code base with a lot of actors and moving parts, I'd like to enforce proper configuration of plugins.

My current idea was to use the maven-enforcer-plugin with the rule RequirePluginVersions. However this fails if the plugin-version is defined within the tile, as the enforcer plugin searches through all parent poms, which seems to exclude the tiles.

Q: Am I simply missing some configuration or is there a better way of doing this?

My configurations:

  • Maven 3.6.3

  • build with bash on windows

parent-pom:

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.my.company</groupId>
  <artifactId>missing_warning_root_pom</artifactId>
  <version>1.0.0</version>
  <packaging>pom</packaging>

  <build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>3.3.0</version>
            </plugin>       
            
            <!-- reproduce plugin management as done by maven 3.6.3 anyway -->
            <plugin>...</plugin>        
      </plugins>
    </pluginManagement>
  </build>

payload-tile:

<project>   
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>3.2.1</version>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        
    </build>
</project>

enforcer-tile:

<project>   
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <executions>
                    <execution>
                        <id>enforce-plugin-version-management</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <fail>true</fail> <!-- fail the build in case any rule is broken. This is the default, but added for clarity's sake -->
                            <rules>
                                <requireMavenVersion><version>3.6.3</version>                               </requireMavenVersion>
                                <requirePluginVersions>
                                    <message>Best Practice is to always define plugin versions!</message>                                   <phases>clean,verify,deploy,site</phases> <!-- life cycle phases during which bound plugins are searched -->
                                </requirePluginVersions>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

and finally the child pom:

....
<modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>com.my.company</groupId>
    <artifactId>missing_warning_root_pom</artifactId>
    <version>1.0.0</version>
    <relativePath>../..</relativePath>
  </parent>


  <groupId>com.my.company</groupId>
  <artifactId>regular_case-proj</artifactId>
  <version>1.0-SNAPSHOT</version>
 
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
 
     <build>
        <plugins>
            <plugin>
                <groupId>io.repaint.maven</groupId>
                <artifactId>tiles-maven-plugin</artifactId>
                <version>2.34</version>
                <extensions>true</extensions>
                <configuration>
                <applyBefore>com.my.company:missing_warning_root_pom</applyBefore>
                <buildSmells>dependencymanagement</buildSmells>
                    <tiles>
                        <tile>com.my.company:regular_case-tile:1.0.0</tile>
                        <tile>com.my.company:enforcer-tile:1.0.0</tile>
                    </tiles>
                    <filtering>true</filtering>
                </configuration>
            </plugin>
        </plugins>
    </build>

Looking at the debug info given by the maven-enforcer-plugin during a regular mvn install I figure that the enforcer-plugin tries to resolve the origin of the version to a specific pom.xml-file which would mean my approach is doomed to fail. However I still hope to have overlooked something.

[DEBUG] All Plugins in use: [Plugin [org.apache.maven.plugins:maven-compiler-plugin], Plugin [io.repaint.maven:tiles-maven-plugin], Plugin [org.apache.maven.plugins:maven-surefire-plugin], Plugin [org.apache.maven.plugins:maven-jar-plugin], Plugin [org.apache.maven.plugins:maven-clean-plugin], Plugin [org.apache.maven.plugins:maven-install-plugin], Plugin [org.apache.maven.plugins:maven-source-plugin], Plugin [org.apache.maven.plugins:maven-site-plugin], Plugin [org.apache.maven.plugins:maven-resources-plugin], Plugin [org.apache.maven.plugins:maven-deploy-plugin], Plugin [org.apache.maven.plugins:maven-enforcer-plugin]]
[DEBUG] pluginWrappers: org.apache.maven.plugins:maven-enforcer-plugin:3.3.0 source: <path-to-my-m2-repo>\missing_warning_root_pom\1.0.0\missing_warning_root_pom-1.0.0.pom
[DEBUG] pluginWrappers: io.repaint.maven:tiles-maven-plugin:2.34 source: C:\workspaces\Alicias_Beispiele\missing-plugin-version-maven-warning\false-positive\false-positive-proj\pom.xml
[DEBUG] pluginWrappers: org.apache.maven.plugins:maven-clean-plugin:2.5 source: <path-to-my-m2-repo>\missing_warning_root_pom\1.0.0\missing_warning_root_pom-1.0.0.pom
[DEBUG] pluginWrappers: org.apache.maven.plugins:maven-resources-plugin:2.6 source: <path-to-my-m2-repo>\missing_warning_root_pom\1.0.0\missing_warning_root_pom-1.0.0.pom
[DEBUG] pluginWrappers: org.apache.maven.plugins:maven-jar-plugin:2.4 source: <path-to-my-m2-repo>\missing_warning_root_pom\1.0.0\missing_warning_root_pom-1.0.0.pom
[DEBUG] pluginWrappers: org.apache.maven.plugins:maven-compiler-plugin:3.1 source: <path-to-my-m2-repo>\missing_warning_root_pom\1.0.0\missing_warning_root_pom-1.0.0.pom
[DEBUG] pluginWrappers: org.apache.maven.plugins:maven-surefire-plugin:2.12.4 source: <path-to-my-m2-repo>\missing_warning_root_pom\1.0.0\missing_warning_root_pom-1.0.0.pom
[DEBUG] pluginWrappers: org.apache.maven.plugins:maven-install-plugin:2.4 source: <path-to-my-m2-repo>\missing_warning_root_pom\1.0.0\missing_warning_root_pom-1.0.0.pom
[DEBUG] pluginWrappers: org.apache.maven.plugins:maven-deploy-plugin:2.7 source: <path-to-my-m2-repo>\missing_warning_root_pom\1.0.0\missing_warning_root_pom-1.0.0.pom
[DEBUG] pluginWrappers: org.apache.maven.plugins:maven-site-plugin:3.3 source: <path-to-my-m2-repo>\missing_warning_root_pom\1.0.0\missing_warning_root_pom-1.0.0.pom
[DEBUG] pluginWrappers: org.apache.maven.plugins:maven-enforcer-plugin:3.3.0 source: <path-to-my-m2-repo>\missing_warning_root_pom\1.0.0\missing_warning_root_pom-1.0.0.pom
[DEBUG] pluginWrappers: org.apache.maven.plugins:maven-site-plugin:3.3 source: <path-to-my-m2-repo>\missing_warning_root_pom\1.0.0\missing_warning_root_pom-1.0.0.pom
[DEBUG] pluginWrappers: org.apache.maven.plugins:maven-resources-plugin:2.6 source: <path-to-my-m2-repo>\missing_warning_root_pom\1.0.0\missing_warning_root_pom-1.0.0.pom
[DEBUG] pluginWrappers: org.apache.maven.plugins:maven-compiler-plugin:3.1 source: <path-to-my-m2-repo>\missing_warning_root_pom\1.0.0\missing_warning_root_pom-1.0.0.pom
[DEBUG] pluginWrappers: org.apache.maven.plugins:maven-surefire-plugin:2.12.4 source: <path-to-my-m2-repo>\missing_warning_root_pom\1.0.0\missing_warning_root_pom-1.0.0.pom
[DEBUG] pluginWrappers: org.apache.maven.plugins:maven-jar-plugin:2.4 source: <path-to-my-m2-repo>\missing_warning_root_pom\1.0.0\missing_warning_root_pom-1.0.0.pom
[DEBUG] pluginWrappers: org.apache.maven.plugins:maven-clean-plugin:2.5 source: <path-to-my-m2-repo>\missing_warning_root_pom\1.0.0\missing_warning_root_pom-1.0.0.pom
[DEBUG] pluginWrappers: org.apache.maven.plugins:maven-install-plugin:2.4 source: <path-to-my-m2-repo>\missing_warning_root_pom\1.0.0\missing_warning_root_pom-1.0.0.pom
[DEBUG] pluginWrappers: org.apache.maven.plugins:maven-deploy-plugin:2.7 source: <path-to-my-m2-repo>\missing_warning_root_pom\1.0.0\missing_warning_root_pom-1.0.0.pom
[DEBUG] checking for notEmpty and notIsWhitespace(): 3.1
[DEBUG] checking for notEmpty and notIsWhitespace(): 3.1
[DEBUG] checking for notEmpty and notIsWhitespace(): 2.34
[DEBUG] checking for notEmpty and notIsWhitespace(): 2.12.4
[DEBUG] checking for notEmpty and notIsWhitespace(): 2.12.4
[DEBUG] checking for notEmpty and notIsWhitespace(): 2.4
[DEBUG] checking for notEmpty and notIsWhitespace(): 2.4
[DEBUG] checking for notEmpty and notIsWhitespace(): 2.5
[DEBUG] checking for notEmpty and notIsWhitespace(): 2.5
[DEBUG] checking for notEmpty and notIsWhitespace(): 2.4
[DEBUG] checking for notEmpty and notIsWhitespace(): 2.4
[DEBUG] plugin org.apache.maven.plugins:maven-source-plugin not found
[DEBUG] checking for notEmpty and notIsWhitespace(): 3.3
[DEBUG] checking for notEmpty and notIsWhitespace(): 3.3
[DEBUG] checking for notEmpty and notIsWhitespace(): 2.6
[DEBUG] checking for notEmpty and notIsWhitespace(): 2.6
[DEBUG] checking for notEmpty and notIsWhitespace(): 2.7
[DEBUG] checking for notEmpty and notIsWhitespace(): 2.7
[DEBUG] checking for notEmpty and notIsWhitespace(): 3.3.0
[DEBUG] checking for notEmpty and notIsWhitespace(): 3.3.0
[DEBUG] Finish Rule 1: org.apache.maven.enforcer.rules.RequirePluginVersions takes 52 ms
0

There are 0 best solutions below