2014-11-16 40 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

非常感谢您的帮助。错误信息颇具误导性.... –

相关问题