In gradle, how to make an existing task "build" depending on the publishing tasks of another module?

1.8k views Asked by At

When I try to declare the task "build" depends on another task like this:

task("build").dependsOn(
    gradle.includedBuild("splain").task("publishToMavenLocal")
)

I got the following error:

FAILURE: Build failed with an exception.

* Where:
Build file '/home/peng/git/shapesafe/build.gradle.kts' line: 35

* What went wrong:
Cannot add task 'build' as a task with that name already exists.

How to fix it?

UPDATE 1: this also doesn't work:

    tasks {
        build.dependsOn(

            gradle.includedBuild("splain").publishToMavenLocal
        )
    }

e: /home/peng/git/shapesafe/build.gradle.kts:92:15: Unresolved reference: dependsOn

UPDATE 2 the following compiles successfully, but gives a different error:


    tasks.build{
        dependsOn(
            gradle.includedBuild("splain").task("publishToMavenLocal")
        )
    }


FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':core:compileTestScala'.
> Could not resolve all task dependencies for configuration ':core:scalaCompilerPlugins'.
   > Could not resolve io.tryp:splain_2.13.8:1.1.0-SNAPSHOT.
     Required by:
         project :core
      > Could not resolve io.tryp:splain_2.13.8:1.1.0-SNAPSHOT.
         > Unable to load Maven meta-data from https://dl.bintray.com/kotlin/kotlin-dev/io/tryp/splain_2.13.8/1.1.0-SNAPSHOT/maven-metadata.xml.
            > Could not GET 'https://dl.bintray.com/kotlin/kotlin-dev/io/tryp/splain_2.13.8/1.1.0-SNAPSHOT/maven-metadata.xml'. Received status code 502 from server: Bad Gateway

This is problematic as io.tryp:splain_2.13.8:1.1.0-SNAPSHOT should already be published to maven local, the gradle task sequence log further confirmed this view:

:splain:buildSrc:compileKotlin
:splain:buildSrc:compileJava
:splain:buildSrc:compileGroovy
:splain:buildSrc:pluginDescriptors
:splain:buildSrc:processResources
:splain:buildSrc:classes
:splain:buildSrc:inspectClassesForKotlinIC
:splain:buildSrc:jar
:splain:buildSrc:assemble
:splain:buildSrc:compileTestKotlin
:splain:buildSrc:pluginUnderTestMetadata
:splain:buildSrc:compileTestJava
:splain:buildSrc:compileTestGroovy
:splain:buildSrc:processTestResources
:splain:buildSrc:testClasses
:splain:buildSrc:test
:splain:buildSrc:validatePlugins
:splain:buildSrc:check
:splain:buildSrc:build
(no publishToMavenLocal!)

So I just need to trigger it

1

There are 1 answers

2
minh tri Vo On

According to the Gradle document at https://docs.gradle.org/current/userguide/composite_builds.html#included_build_task_dependencies, the task name you are using is missing the colon :. It should be:

tasks.findByPath(":configuration")?.dependsOn( gradle.includedBuild("splain").task(":publishToMavenLocal"))

Edit: the depending task should be :configuration task