I'm trying to use "if" ant tasks within maven build.
I found many articles that suggest using "ant-nodeps" dependency. Eventually all this tricks did not work on maven3 + ant 1.8.1 + maven-antrun-plugin 1.6.
"An Ant BuildException has occured: Problem: failed to create task or type if"
Can anything help?
Here's real code (rather, it is not necessary, 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"/>
开发者_Python百科 </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>
1) Add this line before ant tasks in target section:
<taskdef resource="net/sf/antcontrib/antlib.xml"
classpathref="maven.plugin.classpath" />
2) Add exactly the following dependencies to 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>
See my question here where I had the same problem.
I solved it by moving my ant-contrib dependency from the plugin to the project.
精彩评论