Come faccio a impedire Maven accumulo fallire su fallimento compito Ant?
-
28-09-2019 - |
Domanda
Sto utilizzando il FTP Ant compito con 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>
...
Il problema è che la mia generazione non quando la cartella $ {} ftp.server.remotedir non esiste.
Ho cercato di specificare
skipFailedTransfers="true"
ignoreNoncriticalErrors="true
, ma questi non risolvono il problema e la costruzione mantiene in mancanza.
An Ant BuildException has occured: could not change remote directory: 550 /myBadDir: The system cannot find the file specified.
Sai come istruire il mio accumulo Maven per fare non si preoccupano di questo errore task Ant / o sulle modalità di controllo Ant per non fallire nel caso di una directory mancante?
Modifica
.
di opere soluzione Peter
Se un problema come
[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 esclude formica da 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>
Soluzione
Forse avete bisogno di pensare più come Ant e meno come Maven in questo caso.
Ecco una soluzione. Utilizzare il ant-contrib TryCatch compito. Ecco un esempio pom.xml. Copiare il blocco di codice in un file denominato pom.xml
ed eseguire mvn validate
per vedere il lavoro.
<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>
Altri suggerimenti
Dato che Maven-antrun-plugin 1.7 è possibile aggiungere nella configurazione del tag FailOnError
<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>