maven-3maven-antrun-plugin

Maven antrun plugin missing target task after combining from multiple profiles


This is quite an interesting problem I have 2 profiles as defined below. I'm using Maven 3.6.3 with the latest Java 11.

<profiles>
  <profile>
    <id>assembly-unzip</id>
    <build>
      <plugins>          
        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <executions>
            <execution>
              <phase>validate</phase>
              <goals>
                <goal>run</goal>
              </goals>
              <configuration>
                <target>
                  <unzip src="src1.zip" dest="dest10" />
                  <copy  file="copy1.txt" todir="dest11"/>
                </target>
              </configuration>              
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
  </profile>   
  <profile>
    <id>assembly-get</id>
    <build>
      <plugins>
        <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <executions>
            <execution>
              <phase>validate</phase>
              <goals>
                <goal>run</goal>
              </goals>
              <configuration>
                <target>
                  <mkdir dir="download" />
                  <get src="src20" dest="dest"/>
                  <unzip src="dest/src20}" dest="dest"/>
                  <get src="src21" dest="dest"/>
                  <unzip src="dest/src21}" dest="dest"/>                  
                </target>
              </configuration>
            </execution>
          </executions>
        </plugin>        
      </plugins>
    </build>
  </profile>     
</profiles>

When I activate BOTH profiles, I get from (-X) that Maven combines the 2 antrun plugin configurations into a single configuration that looks like this:

<configuration>
  <exportAntProperties default-value="false"/>
  <failOnError default-value="true"/>
  <localRepository>${localRepository}</localRepository>
  <mavenProject default-value="${project}"/>
  <pluginArtifacts>${plugin.artifacts}</pluginArtifacts>
  <session default-value="${session}"/>
  <skip default-value="false">${maven.antrun.skip}</skip>
  <sourceRoot>${sourceRoot}</sourceRoot>
  <target>
    <mkdir dir="download"/>
    <get src="src20" dest="dest"/>
    <unzip src="dest/src20}" dest="dest"/>
    <get src="src21" dest="dest"/>
    <unzip src="dest/src21}" dest="dest"/>
    <copy  file="copy1.txt" todir="dest11"/>
  </target>
  <testSourceRoot>${testSourceRoot}</testSourceRoot>
  <versionsPropertyName default-value="maven.project.dependencies.versions"/>
</configuration>

What's missing from the combined configuration is:

<unzip src="src1.zip" dest="dest10" />

I've tried this multiple times in different ways and the long and short of it is that it seems like if the from the 1st profile that Maven processes has an task (for example) then any tasks in the of the 2nd profile will be ignored and NOT part of the combined configuration. Please be aware that i'm just using as an example. I've tried it with other tasks and see the same behavior.

Any thoughts?


Solution

  • You can do two things:

    1. Use an <id> to each of your execution: without it, you get the default, and that's what maven use to determine duplicate configuration items when it merge them.
    2. Use combine.children and so on. I would advise you not to do that, but you may read more on blog.sonatype.com or at maven.apache.org.

    You could also directly use the power of ant, create target and invoke it conditionally using condition.