Problems with project dependencies when using Gradle with Ant

(Nho Jotom) #1

I have a repository with multiple projects. Our existing build infrastructure is Ant and I’m converting our build to Gradle, so I’m using “ant.importBuild ‘build.xml’”. I’m trying to set dependencies on these projects. Some projects are libraries which I use ‘gradle jar’ to build and they produce JARs. Some are applications which I use ‘gradle dist’ to build and they produce EE artifacts (e.g. .ear). Here is what my repo looks like:

/service/Service1 /shared/SharedLib

I have SharedLib building fine. I want to put a dependency on SharedLib in Service1 so when I run ‘gradle dist’ in Service1, SharedLib builds also if it isn’t built. I’ve tried two different things in Service1’s build.gradle:

dependencies {

compile (’:shared/SharedLib’) }

but this doesn’t work. I get this error:

Could not find method compile() for arguments [project ‘:shared/SharedLib’

Probably because I’m not using the Java plugin as it will cause Gradle to add tasks which conflict with the Ant targets. I tried using jar instead of compile, but this didn’t work either. The other thing I tried was:

task dist(dependsOn: ‘:shared/SharedLib:jar’) << { }

this builds shared/SharedLib, but doesn’t execute Service1’s build. I’m guessing this is overriding Service1’s dist target. BTW, I tried this also:

task dist(overwrite: false, dependsOn: ‘:shared/SharedLib:jar’) << { }

but it still failed.

What’s the best way to handle this?

(Nho Jotom) #2

Any suggestions here?

(Peter Niederwieser) #3

Project dependencies aren’t fundamentally about saying that one project should execute before another (execution dependencies are always between tasks), but about saying that some class path of project A should contain some artifacts produced by project B. With some effort you can make this work without using a plugin such as ‘java’, but I don’t think it’s ultimately the right approach in your case.

‘ant.importBuild’ is of limited usefulness in practice. To leverage the full potential of Gradle, you’ll have to write a Gradle build from scratch. Often this is done inside out (compile-test-bundle-etc.). Along the way, artifacts generated by Gradle are compared to those generated by the Ant build. In case Gradle doesn’t provide some required functionality, it’s perfectly fine to reuse an Ant task (rather than Ant build script) and execute it from Gradle.