0
votes

Project foo defines some ant tasks that are used in root project. For composite build:

setting.gradle

includeBuild '../foo'

build.gradle

configurations {
    foo
}

dependencies {
    foo fileTree(dir : '../foo/build/libs', include: ['*.jar'])
}

ant.taskdef(name: 'foo',
        classname: 'mypackage.Foo',
        classpath: configurations.foo.asPath)

The jar of included project foo should be built before evaluating the root project so that the jar will be available in the ant taskdef classpath. How?

but task dependency is in the execution phase, like

  task run {
        dependsOn gradle.includedBuild('../foo').task(':jar')
    }

The jar will be available only after the task is executed, too late.

1

1 Answers

0
votes

You can configure ant taskdef at execution phase, when the included project is already built. e.g.

task run {
    dependsOn gradle.includedBuild('../foo').task(':jar')
    doFirst {
        ant.taskdef(name: 'foo',
            classname: 'mypackage.Foo',
            classpath: configurations.foo.asPath)

        // call your ant target as usual
    }
}

Even if there is a way of configuring evaluation-time dependency on a composite subproject, you will get a great performance degradation of project evaluation. Even a simple task like tasks or projects will require a full build of ant tasks - definetly not something you want