mic*_*son 6 java ant ftp maven-2 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>
...
Run Code Online (Sandbox Code Playgroud)
问题是当$ {ftp.server.remotedir}文件夹不存在时,我的构建失败.
我试图指明
skipFailedTransfers="true"
ignoreNoncriticalErrors="true
Run Code Online (Sandbox Code Playgroud)
但这些并没有解决问题,而且构建仍然失败.
An Ant BuildException has occured: could not change remote directory: 550 /myBadDir: The system cannot find the file specified.
Run Code Online (Sandbox Code Playgroud)
您是否知道如何指示我的maven构建不关心此Ant任务错误/或如何指示Ant在丢失目录时不会失败?
编辑:
彼得的解决方案有效.
如果你有问题的话
[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
Run Code Online (Sandbox Code Playgroud)
只需从ant-contrib中排除ant
<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>
Run Code Online (Sandbox Code Playgroud)
这是一个解决方案.使用ant-contrib trycatch任务.这是一个示例pom.xml.将代码块复制到名为的文件pom.xml并运行mvn validate以查看它是否有效.
<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>
Run Code Online (Sandbox Code Playgroud)