Как предотвратить сбой сборки Maven при сбое задачи Ant? - PullRequest
6 голосов
/ 19 апреля 2010

Я использую задачу FTP Ant с 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>
...

проблема в том, что моя сборка завершается неудачно, когда папка $ {ftp.server.remotedir} не существует.
Я пытался указать

skipFailedTransfers="true"
ignoreNoncriticalErrors="true

но это не решает проблему, и сборка продолжает давать сбой.

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

Знаете ли вы, как указать моей сборке maven, чтобы она не заботилась об этой ошибке задачи Ant / или как настроить Ant на сбой в случае отсутствия каталога?

Edit:
Решение Петра работает.
Если у вас проблема типа

[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

Просто исключите муравья из списка участников

<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>

Ответы [ 2 ]

8 голосов
/ 23 апреля 2010

Возможно, вам нужно думать больше как Муравей , а не как Maven в этом случае.

Вот одно из решений. Используйте задачу 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>
1 голос
/ 10 ноября 2016

Начиная с maven-antrun-plugin 1.7 вы можете добавить в конфигурацию тег 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>
...