一千萬個為什麽

搜索

如何在Ant任務失敗時阻止Maven構建失敗?

I'm using the FTP Ant task with maven-antrun-plugin


    org.apache.maven.plugins
    maven-antrun-plugin
    
        
            ftp
            generate-resources
            
                
                    
                        
                            
                        
                    
                
            
            
                run
            
        
    
...

問題是當$ {ftp.server.remotedir}文件夾不存在時,我的構建失敗 我試圖指明

skipFailedTransfers="true"
ignoreNoncriticalErrors="true

but these don't fix the problem and the build keeps failing.

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

您是否知道如何指示我的maven構建不關心此Ant任務錯誤/或如何指示Ant在丟失目錄時不會失敗?

Edit:
Peter's solution works.
If you 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

只需從ant-contrib中排除ant


    ant-contrib
    ant-contrib
    ${ant-contrib.ver}
    
        
            ant
            ant
         
    

最佳答案

也許您需要更像 Ant ,而不是像 Maven

這是一個解決方案。使用 ant-contrib trycatch 任務。這是一個示例pom.xml。將代碼塊復制到名為 pom.xml 的文件中,然後運行 mvn validate 以查看它是否有效。




  4.0.0
  com.stackoverflow.q2666794
  trycatch
  jar
  1.0-SNAPSHOT
  trycatch
  http://maven.apache.org
  
    
      
        org.apache.maven.plugins
        maven-antrun-plugin
        1.3
        
          
            trycatch
            validate
            
              
                
                <trycatch>
                  <try>
                    Failing ftp task should go here
                  
                  
                    See the error was caught and ignored
                  
                
              
            
            
              run
            
          
        
        
          
            ant-contrib
            ant-contrib
            1.0b3
            
              
                ant
                ant
              
            
          
        
      
    
  

轉載註明原文: 如何在Ant任務失敗時阻止Maven構建失敗?