I am using Apache Maven 3.8.4 with Java version: 11.0.5 and I have an execution of org.apache.maven.plugins:maven-antrun-plugin:1.7 that is working fine, to produce a MANIFEST.mf file in the target directory:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.plugin.classpath"/>
<if>
<available file="${project.basedir}/src/main/resources/META-INF/MANIFEST.MF"/>
<then>
<copy file="${project.basedir}/src/main/resources/META-INF/MANIFEST.MF" tofile="${manifest.path}"/>
</then>
</if>
<if>
<equals arg1="${project.packaging}" arg2="jar"/>
<then>
<echo file="${manifest.path}" append="true">Module-Name: ${project.artifactId}${line.separator}</echo>
<!-- some other echos here-->
</then>
</if>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<exclusions>
<exclusion>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</plugin>
Basically I first check if a MANIFEST.mf file is already in the source code. If so, I copy its content under the target directory first.
Then, if the packaging of the project is jar, I will append some lines to the manifest file that I just copied (or created) in the target directory.
I now have a new requirement, which is to produce a MANIFEST.mf file over test compile which is different than the one for the sources.
So I added the following to the above block:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.plugin.classpath"/>
<if>
<available file="${project.basedir}/src/main/resources/META-INF/MANIFEST.MF"/>
<then>
<copy file="${project.basedir}/src/main/resources/META-INF/MANIFEST.MF" tofile="${manifest.path}"/>
</then>
</if>
<if> <!--NEW: add the same logic for tests-->
<available file="${project.basedir}/src/test/resources/META-INF/MANIFEST.MF"/>
<then>
<copy file="${project.basedir}/src/test/resources/META-INF/MANIFEST.MF" tofile="${test.manifest.path}"/>
</then>
</if>
<if>
<equals arg1="${project.packaging}" arg2="jar"/>
<then>
<!--Production-->
<echo file="${manifest.path}" append="true">Module-Name: ${project.artifactId}${line.separator}</echo>
<!-- other production echos here-->
<!--Test-->
<echo file="${test.manifest.path}" append="true">Module-Name: ${project.artifactId}${line.separator}</echo>
<!-- other test echos here -->
</then>
</if>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<exclusions>
<exclusion>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</plugin>
However, when I try to compile my code, it outputs the following exception:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (default) on project my-project: An Ant BuildException has occured: You must not nes t more than one condition into [ERROR] around Ant part ...... @ 11:7 in D:\my-project\target\antrun\build-main.xml [ERROR] -> [Help 1]
If I go check the content of the file D:\my-project\target\antrun\build-main.xml, I can see that at the indicated line there is an additional condition added to the second if block:
Basically, it appears like the antrun plugin is parsing the second and third if block in parallel, which ends up into mixing up stuff and specifically, adding two conditions to the second if block.
I have no clue what's going on, does anyone have an idea please?
