>我在创建蚂蚁任务时遇到问题,不知道发生了什么。
这是我的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 的类。
不幸的是,我没有找到谷歌的任何提示.....
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)
}