Maven3 - maven-antrun-plugin - "failed to create task or type if"

I am trying to use "if" ant tasks in maven build.

I found many articles that suggest using the ant -nodeps dependency. In the end, all these tricks did not work on maven3 + ant 1.8.1 + maven-antrun-plugin 1.6.

"Ant BuildException event raised: Problem: Could not create task or type if"

Can anything help?

Here is the real code (rather, it is not needed, but just in case):

<profiles> <profile> <id>smtpConfigurationProfile</id> <activation> <activeByDefault>true</activeByDefault> </activation> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.6</version> <executions> <execution> <phase>validate</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <if> <isset property="${smtpFile}"/> <then> <delete file="${project.build.outputDirectory}/smtp.properties"/> <copy file="${smtpFile}" tofile="${project.build.outputDirectory}/smtp.properties"/> </then> <elseif> <isset property="${smtpProfile}"/> <then> <delete file="${project.build.outputDirectory}/smtp.properties"/> <copy file="src/main/resources/${smtpProfile}.smtp.properties" tofile="${project.build.outputDirectory}/smtp.properties"/> </then> <else> <delete file="${project.build.outputDirectory}/smtp.properties"/> <copy file="src/main/resources/production.smtp.properties" tofile="${project.build.outputDirectory}/smtp.properties"/> </else> </elseif> </if> </tasks> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>org.apache.ant</groupId> <artifactId>ant-nodeps</artifactId> <version>1.8.1</version> </dependency> </dependencies> </plugin> </plugins> </build> </profile> </profiles> 
+7
source share
2 answers

1) Add this line to ant tasks in the target section:

 <taskdef resource="net/sf/antcontrib/antlib.xml" classpathref="maven.plugin.classpath" /> 

2) Add the following dependencies to the plugin:

  <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> <dependency> <groupId>org.apache.ant</groupId> <artifactId>ant-nodeps</artifactId> <version>1.8.1</version> </dependency> </dependencies> 
+17
source

See my question here where I had the same problem.

I solved this by moving my ant -contrib dependency from the plugin to the project.

+2
source

All Articles