Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"/>
                                            </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>
like image 598
Oleg Chirukhin Avatar asked Jan 21 '11 14:01

Oleg Chirukhin


2 Answers

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>
like image 135
Oleg Chirukhin Avatar answered Nov 23 '22 23:11

Oleg Chirukhin


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.

like image 21
Qwerky Avatar answered Nov 23 '22 22:11

Qwerky