Import 2 Ant build files into a Gradle file


(Gloria Santin) #1

I need to create 2 ear files using a gradle build file. The Ear files were originally built using Ant. They are part of the same project. The project has 2 different build files. However, when the ears are built they both use common ant tasks to build.
In my Gradle file, I can import one build file (build1.xml) and call the ant tasks to compile and stage the ear.
But I need to import an second ant build file (build2.xml) and call the similar ant tasks but using build2.xml as a starting point.
Is there a way to import 2 ant build files and when I call the ant tasks, make sure they reference the correct build file?

UPDATE
I trying to use the gradle task ant.importBuild and assign the ant tasks that I want to do for each build script.
This is the code I have:

ant.importBuild("build-remote.xml", { antTargetName ->
   antTargetName == "clean-all" ? "remoteClean" : antTargetName
})

ant.importBuild("build.xml", { antTargetName ->
    antTargetName == "clean-compile" ? "loadClean" : antTargetName
}) 

task cleanBothBuilds(dependsOn: ["remoteClean", "loadClean"])

I get the error that Task with path ‘remoteClean’ not found in root project


(Gloria Santin) #2

If anyone is thinking of this approach, I don’t think it is viable. We solved it by creating a multi project build. Each ant build has its own gradle build script and a parent build script calls them.