Continuing old discussions from the old forum, i’m still having trouble to import a legacy ant file and use it from a custom gradle plugin.
The ant file has the following explicit check, done from a sub ant file (check.xml), imported from my general ant xml file (build.xml)
<echo message="checking that the Ant If and For tasks are available for Ant" level="info"/>
<!-- ensure that the If task is defined, otherwise everything would fail -->
<condition property="IfTaskAvailable">
<available classname="net.sf.antcontrib.logic.IfTask"/>
</condition>
<fail message="The If task is not defined, please add ant-contrib jar file as a -lib parameter to ant or within your class path" unless="IfTaskAvailable"/>
<!-- ensure that the For task is defined, otherwise everything would fail -->
<condition property="ForAvailable">
<or>
<available classname="net.sf.antcontrib.logic.For"/>
<available classname="net.sf.antcontrib.logic.ForTask"/>
</or>
</condition>
<fail message="The For task is not defined, please add ant-contrib jar file as a -lib parameter to ant or within your class path" unless="ForAvailable"/>
<!-- Ant-contrib ant tasks definition -->
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<echo message=" ... OK : Ant If and For tasks loaded ..." level="info"/>
I’m doing this in my gradle plugin:
project.configurations{
antcp {
description = 'ant classpath'
transitive = true
exclude module: 'ant'
}
}
project.dependencies{
// add ant contrib and pmd
antcp 'pmd:pmd:4.2.5'
antcp 'ant-contrib:ant-contrib:1.0b3'
}
project.ant.taskdef(uri:'antlib:net.sf.antcontrib', resource:'net/sf/antcontrib/antcontrib.properties', classpath: project.configurations.antcp.asPath)
project.ant.importBuild('my main build.xml file')
project.ant.antProject.executeTarget('myTarget')
It kind of works, since I see in the log output
[DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Finding class net.sf.antcontrib.logic.IfTask
[DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Loaded from xxx/caches/modules-2/files-2.1/ant-contrib/ant-contrib/1.0b3/943cd5c8802b2a3a64a010efb86ec19bac142e40/ant-contrib-1.0b3.jar net/sf/antcontrib/logic/IfTask.class
[DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Class net.sf.antcontrib.logic.IfTask loaded from ant loader (parentFirst)
But then, the ant available
check fails anyway
[INFO] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:echo] checking that the Ant If and For tasks are available for Ant
[DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:available] class “net.sf.antcontrib.logic.IfTask” was not found
[DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:available] Unable to load class net.sf.antcontrib.logic.IfTask
[DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Condition false; not setting IfTaskAvailable
[DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:fail] failing due to The If task is not defined, please add ant-contrib jar file as a -lib parameter to ant or within your class path
I can provide more details on the ant build file or my plugin, but I don’t understand why this does not work.
The IfTask (among other tasks from the ant contrib jar) is well ‘imported’
I load the main ant build.xml file and call the default target
It calls the secondary xml file, that contains the <available/>
check on the IfTask, that fails