How to prevent Maven build crashes when Ant task crashes?

I am using FTP Ant task with maven-antrun-plugin

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>ftp</id> <phase>generate-resources</phase> <configuration> <tasks> <ftp action="get" server="${ftp.server.ip}" userid="${ftp.server.userid}" password="${ftp.server.password}" remotedir="${ftp.server.remotedir}" depends="yes" verbose="yes" skipFailedTransfers="true" ignoreNoncriticalErrors="true"> <fileset dir="target/test-classes/testdata"> <include name="**/*.html" /> </fileset> </ftp> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> ... 

The problem is that my build failed when the folder $ {ftp.server.remotedir} does not exist.
I tried to specify

 skipFailedTransfers="true" ignoreNoncriticalErrors="true 

but this does not fix the problem and the assembly continues to fail.

 An Ant BuildException has occured: could not change remote directory: 550 /myBadDir: The system cannot find the file specified. 

Do you know how to instruct my maven assembly, don't care about this Ant error, or how to tell Ant not to fail if there is no directory?

Edit:
Peter's decision. If you have a problem like

 [INFO] Error configuring: org.apache.maven.plugins:maven-antrun-plugin. Reason: java.lang.NoSuchMethodError: org.apache.tools.ant.util.FileUtils.close(Ljava/io/InputStream;)V 

Just exclude Ant from ant -contrib

 <dependency> <groupId>ant-contrib</groupId> <artifactId>ant-contrib</artifactId> <version>${ant-contrib.ver}</version> <exclusions> <exclusion> <groupId>ant</groupId> <artifactId>ant</artifactId> </exclusion> </exclusions> </dependency> 
+6
java maven-2 maven-antrun-plugin ant ftp
source share
2 answers

You may need to think more about Ant and less than Maven in this case.

Here is one solution. Use ant-contrib trycatch . Here is an example pom.xml. Copy the block of code into a file called pom.xml and run mvn validate to see how it works.

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.stackoverflow.q2666794</groupId> <artifactId>trycatch</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>trycatch</name> <url>http://maven.apache.org</url> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.3</version> <executions> <execution> <id>trycatch</id> <phase>validate</phase> <configuration> <tasks> <taskdef resource="net/sf/antcontrib/antcontrib.properties"/> <trycatch> <try> <fail>Failing ftp task should go here</fail> </try> <catch> <echo>See the error was caught and ignored</echo> </catch> </trycatch> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>ant-contrib</groupId> <artifactId>ant-contrib</artifactId> <version>1.0b3</version> <exclusions> <exclusion> <artifactId>ant</artifactId> <groupId>ant</groupId> </exclusion> </exclusions> </dependency> </dependencies> </plugin> </plugins> </build> </project> 
+8
source share

Since maven-antrun-plugin 1.7 you can add tag failOnError to the configuration

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>ftp</id> <phase>generate-resources</phase> <configuration> <failOnError>false</failOnError> <tasks> <ftp action="get" server="${ftp.server.ip}" userid="${ftp.server.userid}" password="${ftp.server.password}" remotedir="${ftp.server.remotedir}" depends="yes" verbose="yes" skipFailedTransfers="true" ignoreNoncriticalErrors="true"> <fileset dir="target/test-classes/testdata"> <include name="**/*.html" /> </fileset> </ftp> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> 
0
source share

All Articles