Depending on publish tasks

Hi,

I am running Gradle 2.5 and have a multi-project with project dependencies among the subprojects. One of them performs some integration using a nested Gradle process, which cannot access the artifacts of dependencies, because project dependencies cannot work outside the multi-project, of course.

One solution is to publish all other components first before running the nested Gradle build, but I need to avoid publishing artifacts before all tests are successful.

Therefore I tried the following:

  1. Define an additional local repository for publishing
  2. Call just the publish task for this repository for all depending projects.
  3. Make the nested Gradle build use this local repository.
  4. Publish all projects to the actual repository afterwards.

I have some problems doing this:

  • PublishToIvyRepository tasks do not exist by default. It is impossible to run :myproj:someIntegrationTest and have that trigger certain publish tasks, because those tasks are not even created when not actually calling publish as build task.

  • When publish is mentioned as task when calling Gradle, those tasks will magically be created by some rule, but from the old world it is still not possible to use dependsOn and have that working

    tasks.withType(MyIntegrationTask) { integration ->
    rootProject.subprojects.findAll { it.name != ‘myproj’ }.each { sub ->
    sub.tasks.withType(PublishToIvyRepository)
    .matching { it.repository.name == ‘tmp’ }
    .all { pub ->
    println "$integration.path dependsOn $pub.path"
    integration.dependsOn pub
    }
    }
    }

This will println that the dependencies are successfully established, but running gradlew :myproj:someIntegrationTest publish will still execute those publish tasks after the integration test.

How do I do dependsOn properly with publish tasks? Would updating Gradle to 2.7 help here?

“When publish is mentioned as task when calling Gradle, those tasks will magically be created by some rule, but from the old world it is still not possible to use dependsOn and have that working”

Short story:
There is a bridge being developed right now, to bridge between the tasks from the project space to the tasks from the model space, and vice versa.
This will allow your ‘withType’ construct to work.

And [here] (https://github.com/gradle/gradle/blob/master/design-docs/task-bridging.md) is the design doc corresponding to this story, for those interested

Thanks a lot for the info.

As this bridging mechanism is not in place yet, is there another possibility for me? Can I configure those dependencies for my (legacy) task in the new model space?

You can read this to find a potential workaround for your problem.
Note that the bridging mechanism for tasks from both worlds will most likely be available on 2.8. You might want to wait for it.

tasks.realize() did help as a workaround, thanks!

Looking forward to Gradle 2.8 :smile:

I just tried this with Gradle 2.8 and can’t get it to work.

apply plugin: 'java'
apply plugin: 'ivy-publish'

group = 'test'
version = 'test'

publishing {
    repositories {
        ivy {
            url file('repo').toURI().toURL()
        }
    }
}

def foo = task('foo')

// first try
tasks.withType(PublishToIvyRepository) {
    foo.dependsOn it
}

// second try
foo.dependsOn tasks.withType(PublishToIvyRepository)

Executing foo with Gradle 2.8 does not execute any publish tasks:

D:\test>gradlew foo
:foo UP-TO-DATE

BUILD SUCCESSFUL

Am I doing it wrong?