与ant的componentdef错误

时间:2010-10-30 20:06:20

标签: grails ant groovy build

我有一个相对较旧的Grails应用程序,它使用ant来构建应用程序。在测试服务器中它构建没有任何问题,但是当我尝试在我的PC上运行它时,我得到一致的错误:

Caused by: jar:file:/C:/ant/apache-ant-1.8.0/lib/ant.jar!/org/apache/tools/ant/antlib.xml:37: Problem: failed to create task or type componentdef
    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.
    at org.apache.tools.ant.UnknownElement.getNotFoundException(UnknownElement.java:484)
        at org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:416)
        at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:160)
        at org.apache.tools.ant.taskdefs.Antlib.execute(Antlib.java:146)
        at org.apache.tools.ant.taskdefs.Definer.loadAntlib(Definer.java:432)
        ... 63 more

我发现错误发生在构建的以下部分:

<macrodef name="grails">
    <attribute name="script"/>
    <attribute name="args" default="" />
    <sequential>
        <grailsTask script="@{script}" args="@{args}" classpathref="grails.classpath">
            <compileClasspath refid="compile.classpath"/>
            <testClasspath refid="test.classpath"/>
            <runtimeClasspath refid="app.classpath"/>
        </grailsTask>
    </sequential>
</macrodef>

如果我发表评论,则不会再出现错误。

进一步参考,这是整个错误转储:

G:\chp\src\hewittportlet\build.xml:131: The following error occurred while executing this line:
G:\chp\src\hewittportlet\build.xml:53: Unable to start Grails: java.lang.reflect.InvocationTargetExc
eption
        at grails.ant.GrailsTask.runGrails(GrailsTask.java:124)
        at grails.ant.GrailsTask.execute(GrailsTask.java:78)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:398)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:390)
        at org.apache.tools.ant.Target.performTasks(Target.java:411)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1360)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1329)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1212)
        at org.apache.tools.ant.Main.runBuild(Main.java:801)
        at org.apache.tools.ant.Main.startAnt(Main.java:218)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at org.codehaus.groovy.grails.cli.support.GrailsBuildHelper.execute(GrailsBuildHelper.java:9
4)
        at grails.ant.GrailsTask.runGrails(GrailsTask.java:113)
        ... 31 more
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.groovy.grails.cli.support.GrailsBuildHelper.execute(GrailsBuildHelper.java:8
8)
        ... 32 more
Caused by: The following error occurred while executing this line:
jar:file:/C:/ant/apache-ant-1.8.0/lib/ant.jar!/org/apache/tools/ant/antlib.xml:37: Problem: failed t
o create task or type componentdef
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.

        at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:508)
        at org.apache.tools.ant.taskdefs.Definer.loadAntlib(Definer.java:434)
        at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:281)
        at org.apache.tools.ant.ComponentHelper.checkNamespace(ComponentHelper.java:790)
        at org.apache.tools.ant.ComponentHelper.getDefinition(ComponentHelper.java:260)
        at org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:237)
        at org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:216)
        at org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:414)
        at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:160)
        at groovy.util.AntBuilder.nodeCompleted(AntBuilder.java:186)
        at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:147)
        at groovy.util.AntBuilder.doInvokeMethod(AntBuilder.java:154)
        at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:64)
        at org.codehaus.gant.GantBuilder.invokeMethod(GantBuilder.java:89)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
        at org.codehaus.gant.GantBinding.initializeGantBinding(GantBinding.groovy:109)
        at org.codehaus.gant.GantBinding.this$4$initializeGantBinding(GantBinding.groovy)
        at org.codehaus.gant.GantBinding$this$4$initializeGantBinding.callCurrent(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:
44)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:1
43)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:1
47)
        at org.codehaus.gant.GantBinding.<init>(GantBinding.groovy:42)
        at org.codehaus.groovy.grails.cli.GrailsScriptRunner.callPluginOrGrailsScript(GrailsScriptRu
nner.java:355)
        at org.codehaus.groovy.grails.cli.GrailsScriptRunner.executeCommand(GrailsScriptRunner.java:
279)
        at org.codehaus.groovy.grails.cli.GrailsScriptRunner.executeCommand(GrailsScriptRunner.java:
205)
        ... 37 more
Caused by: jar:file:/C:/ant/apache-ant-1.8.0/lib/ant.jar!/org/apache/tools/ant/antlib.xml:37: Proble
m: failed to create task or type componentdef
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.

        at org.apache.tools.ant.UnknownElement.getNotFoundException(UnknownElement.java:484)
        at org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:416)
        at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:160)
        at org.apache.tools.ant.taskdefs.Antlib.execute(Antlib.java:146)
        at org.apache.tools.ant.taskdefs.Definer.loadAntlib(Definer.java:432)
        ... 63 more

Total time: 34 seconds

2 个答案:

答案 0 :(得分:4)

Grails与Ant 1.8不兼容 - 您需要使用1.7.x。

答案 1 :(得分:2)

我找到了问题的根源。

问题不是Ant的版本,而是Grails和缺少脚本的版本。此应用程序使用的是Grails(版本1.1.1)的弃用版本。

以下代码,我为每个人的便利重新列出,是调用脚本。但是,在此特定应用程序中,脚本已被删除,这导致Grails的构建过程崩溃:

<macrodef name="grails">
<attribute name="script"/>
<attribute name="args" default="" />
<sequential>
    <grailsTask script="@{script}" args="@{args}" classpathref="grails.classpath">
        <compileClasspath refid="compile.classpath"/>
        <testClasspath refid="test.classpath"/>
        <runtimeClasspath refid="app.classpath"/>
    </grailsTask>
</sequential>
</macrodef>

解决方案很简单:将Grails升级到更新的版本,例如1.3.5。在那之后构建工作没有问题,即使缺少一些脚本。

我推测这种新行为允许在脚手架中生成脚本,但同时让开发人员可以自由删除不需要的或不必要的脚本。

感谢Burth Beckwith的见解。

Luis Colorado