2014-11-16 63 views
2

我在創建螞蟻任務時遇到問題,不知道發生了什麼。Gradle:未能創建任務或輸入taskDef,名稱未定義

這是我的build.gradle:

apply plugin: 'java' 

/** Create a classpath for the jarbundler ant-task */ 
configurations { 
    jarbundler 
} 

dependencies { 
    jarbundler 'net.sourceforge.jarbundler:jarbundler:2.1.0' 
} 


repositories { 
    maven { 
     url 'http://ooo-maven.googlecode.com/hg/repository' 
    } 
} 


task distMac(dependsOn: assemble) << { 
    println "Create MacOSX distribution....." 
    println "Classpath: " + configurations.jarbundler.asPath 

    ant.taskDef(name: 'jarbundler', 
      classname: 'net.sourceforge.jarbundler.JarBundler', 
      classpath: configurations.jarbundler.asPath) 
} 

其失敗:

Dieters-MBP-3:jdbexp rehdie$ gradle distMac 
:compileJava UP-TO-DATE 
:processResources UP-TO-DATE 
:classes UP-TO-DATE 
:jar UP-TO-DATE 
:assemble UP-TO-DATE 
:distMac 
Create MacOSX distribution..... 
Classpath: /Users/rehdie/.gradle/caches/modules-2/files-2.1/net.sourceforge.jarbundler/jarbundler/2.1.0/84f1fbcf60aeb90560ba3d554b72217c0836935e/jarbundler-2.1.0.jar 
:distMac FAILED 

FAILURE: Build failed with an exception. 

* Where: 
Build file '/Users/rehdie/development/projects/jdbexp/build.gradle' line: 25 

* What went wrong: 
Execution failed for task ':distMac'. 
> Problem: failed to create task or type taskDef 
    Cause: The name is undefined. 
    Action: Check the spelling. 
    Action: Check that any custom tasks/types have been declared. 
    Action: Check that any <presetdef>/<macrodef> declarations have taken place. 


* Try: 
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. 

BUILD FAILED 

Total time: 2.9 secs 

做同樣在Ant文件按預期工作:

<project name="jdbexp_wrapper" default="dist_osx"> 

    <taskdef name="jarbundler" 
      classpath="/Users/rehdie/.gradle/caches/modules-2/files-2.1/net.sourceforge.jarbundler/jarbundler/2.1.0/84f1fbcf60aeb90560ba3d554b72217c0836935e/jarbundler-2.1.0.jar" 
      classname="net.sourceforge.jarbundler.JarBundler"/> 


    <target name="hello"> 
     <echo>Hallo</echo> 
    </target> 

</project> 

有什麼建議嗎?

的jarbundler-JAR存在於/Users/rehdie/.gradle/caches/modules-2/files-2.1/net.sourceforge.jarbundler/jarbundler/2.1.0/84f1fbcf60aeb90560ba3d554b72217c0836935e/jarbundler-2.1.0.jar和它包含一個名爲net.sourceforge.jarbundler.JarBundler的類。

不幸的是我沒有找到任何暗示與谷歌.....

回答

2

taskdef是大小寫敏感的,應該全部小寫:

task distMac(dependsOn: assemble) << { 
    println "Create MacOSX distribution....." 
    println "Classpath: " + configurations.jarbundler.asPath 

    ant.taskdef(name: 'jarbundler', 
      classname: 'net.sourceforge.jarbundler.JarBundler', 
      classpath: configurations.jarbundler.asPath) 
} 
+1

非常感謝您的幫助。錯誤信息頗具誤導性.... –

相關問題