2011-01-21 49 views
7

我想在maven構建中使用「如果」螞蟻任務。maven3 - maven-antrun-plugin - 「未能創建任務或類型,如果」

我發現很多文章都建議使用「ant-nodeps」依賴關係。最終所有這些技巧都不適用於maven3 + ant 1.8.1 + maven-antrun-plugin 1.6。

「的螞蟻BuildException已發生:問題:無法創建任務或類型,如果」

什麼能幫忙嗎?

這裏是真正的代碼(更確切地說,它是沒有必要的,但以防萬一):

<profiles> 
    <profile> 
     <id>smtpConfigurationProfile</id> 
     <activation> 
      <activeByDefault>true</activeByDefault> 
     </activation> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-antrun-plugin</artifactId> 
        <version>1.6</version> 
        <executions> 
         <execution> 
          <phase>validate</phase> 
          <goals> 
           <goal>run</goal> 
          </goals> 
          <configuration> 
           <tasks> 
            <if> 
             <isset property="${smtpFile}"/> 
             <then> 
              <delete file="${project.build.outputDirectory}/smtp.properties"/> 
              <copy file="${smtpFile}" 
                tofile="${project.build.outputDirectory}/smtp.properties"/> 
             </then> 
             <elseif> 
              <isset property="${smtpProfile}"/> 
              <then> 
               <delete file="${project.build.outputDirectory}/smtp.properties"/> 
               <copy file="src/main/resources/${smtpProfile}.smtp.properties" 
                 tofile="${project.build.outputDirectory}/smtp.properties"/> 
              </then> 
              <else> 
               <delete file="${project.build.outputDirectory}/smtp.properties"/> 
               <copy file="src/main/resources/production.smtp.properties" 
                 tofile="${project.build.outputDirectory}/smtp.properties"/> 
              </else> 
             </elseif> 
            </if> 
           </tasks> 
          </configuration> 
         </execution> 
        </executions> 
        <dependencies> 
         <dependency> 
          <groupId>org.apache.ant</groupId> 
          <artifactId>ant-nodeps</artifactId> 
          <version>1.8.1</version> 
         </dependency> 
        </dependencies> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 

回答

17

1)之前,目標節Ant任務添加此行:

<taskdef resource="net/sf/antcontrib/antlib.xml" 
classpathref="maven.plugin.classpath" /> 

2)添加正是以下依賴關係插件:

     <dependencies> 
         <dependency> 
          <groupId>ant-contrib</groupId> 
          <artifactId>ant-contrib</artifactId> 
          <version>1.0b3</version> 
          <exclusions> 
           <exclusion> 
            <groupId>ant</groupId> 
            <artifactId>ant</artifactId> 
           </exclusion> 
          </exclusions> 
         </dependency> 
         <dependency> 
          <groupId>org.apache.ant</groupId> 
          <artifactId>ant-nodeps</artifactId> 
          <version>1.8.1</version> 
         </dependency> 
        </dependencies> 
+0

[taskdef]無法從資源net/sf/antcontrib/antlib.xml加載定義。它找不到。 – 2017-08-30 09:45:59

1

見我的問題here在那裏我有同樣的問題。

我通過將我的ant-contrib依賴從插件移動到項目來解決它。

+0

謝謝Qwerky!但是我發現taskdefs有不同的問題。 – 2011-01-24 07:23:25

相關問題