Dieter Rehbein
Dieter Rehbein

Reputation: 991

Gradle: failed to create task or type taskDef, name is undefined

I have a problem creating an ant-task and have no idea what's going on.

This is my 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)
}

which fails with:

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

Doing the same in an ant-file works as expected:

<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>

Any ideas?

The jarbundler-jar exists at /Users/rehdie/.gradle/caches/modules-2/files-2.1/net.sourceforge.jarbundler/jarbundler/2.1.0/84f1fbcf60aeb90560ba3d554b72217c0836935e/jarbundler-2.1.0.jar and it contains a class named net.sourceforge.jarbundler.JarBundler.

Unfortunately I did not find any hint with google.....

Upvotes: 2

Views: 1615

Answers (1)

Opal
Opal

Reputation: 84786

taskdef is case sensitive and should be all lowercase:

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)
}

Upvotes: 2

Related Questions