repaint-io / maven-tiles

Injecting maven configurations by composition rather than inheritance
155 stars 32 forks source link

Tiles are not applied if POMs packaging tag is set with POM property #139

Open VadimPitenko opened 1 year ago

VadimPitenko commented 1 year ago

Environment Details

Expected behavior

  1. Let's assume we have such POM:
    <?xml version="1.0" encoding="UTF-8"?>
    <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">
     <modelVersion>4.0.0</modelVersion>
     <groupId>example.micronaut</groupId>
     <artifactId>micronautguide</artifactId>
     <version>0.1</version>
     <packaging>${packaging}</packaging>
     ...
     <properties>
       <packaging>jar</packaging>
       ...
     </properties>
     ...
     <build>
       <plugins>
         <plugin>
           <groupId>io.repaint.maven</groupId>
           <artifactId>tiles-maven-plugin</artifactId>
           <version>2.31</version>
           <extensions>true</extensions>
           <configuration>
             <tiles>
               <tile>it.session.maven.tiles:maven-jetty-tile:0.8-SNAPSHOT</tile>
             </tiles>
           </configuration>
         </plugin>
         ...
       </plugins>
     </build>
    </project>
  2. Running mvn clean install triggers it.session.maven.tiles:maven-jetty-tile:0.8-SNAPSHOT, so we can see such logs in console:
    [INFO] --- tiles-maven-plugin: Injecting 1 tiles as intermediary parent artifacts for example.micronaut:micronauttiles...
    [INFO] Mixed 'example.micronaut:micronauttiles:0.1' with tile 'it.session.maven.tiles:maven-jetty-tile:0.8-SNAPSHOT' as its new parent.
    [INFO] Mixed 'it.session.maven.tiles:maven-jetty-tile:0.8-SNAPSHOT' with original parent 'io.micronaut:micronaut-parent:3.8.1' as its new top level parent.

Actual behavior

  1. Define the same POM as is in Expected behavior section.
  2. Run mvn clean install. There will be no expected logs in console. That means that tile is not applied.
  3. However, if we defined packaging explicitly <packaging>jar</packaging>, tile is applied successfully.

Steps to reproduce

  1. Clone the repaint-io/maven-tiles-examples GIT repository.
  2. Install the maven-tiles-examples to local maven repository. Run mvn clean install.

    NOTE: I was unable a build project with tiles-maven-plugin version 1.1-SNAPSHOT, so I've replaced it in each module of the project with 2.31.

  3. Download the example Micronaut application from step 3 of the official quick-start guide.
  4. Add the maven-jetty-tile to your stub Micronaut app:
    <plugin>
     <groupId>io.repaint.maven</groupId>
     <artifactId>tiles-maven-plugin</artifactId>
     <version>2.31</version>
     <extensions>true</extensions>
     <configuration>
       <tiles>
         <tile>it.session.maven.tiles:maven-jetty-tile:0.8-SNAPSHOT</tile>
       </tiles>
     </configuration>
    </plugin>
  5. Build project. Run the mvn clean install.
  6. Verify the output. Check that maven-jetty-tile was not injected.
  7. Specify the packaging tag value explicitly. Change the <packaging>${packaging}</packaging> to <packaging>jar</packaging>.
  8. Build project. Run the mvn clean install.
  9. Verify the output. The next rows presented:
    [INFO] --- tiles-maven-plugin: Injecting 1 tiles as intermediary parent artifacts for example.micronaut:micronauttiles...
    [INFO] Mixed 'example.micronaut:micronauttiles:0.1' with tile 'it.session.maven.tiles:maven-jetty-tile:0.8-SNAPSHOT' as its new parent.
    [INFO] Mixed 'it.session.maven.tiles:maven-jetty-tile:0.8-SNAPSHOT' with original parent 'io.micronaut:micronaut-parent:3.8.1' as its new top level parent.
talios commented 1 year ago

I suspect this is more a maven issue than tiles itself. The tiles extension is triggered from the afterProjectsRead call of AbstractMavenLifecycleParticipant:

Invoked after all MavenProject instances have been created. This callback is intended to allow extensions to manipulate MavenProjects before they are sorted and actual build execution starts.

At this point in time, I suspect the properties have not been resolved (which is known to cause some other limitations/oddities elsewhere) which may be preventing the extension from running.

Is there any particular reason for declaring the packaging type as a property - that seems awfully odd to me.

VadimPitenko commented 1 year ago

Hey @talios, thank you for the quick response!

Absolutely agree with you regarding using properties for packaging :)

However, there is a problem. The organization I'm working in is actively using the Maven Tiles plugin. Also, we use Micronaut. The thing is that Micronaut CLI generates projects with packaging property. So, each time somebody in the organization creates a project they face this issue.

This is not a priority cause we can mitigate it. However, would be nice to fix it.