Composite Build: can not run unit test

I have a project which is using composite build.

project struct:
root-project (name: a)
 - include build project (name: b)
   - project c

I have some unit tests in project c, when I run unit tests in project c, I got a gradle error:
Project ‘c’ not found in project ‘:b’.

But if I open the project b to run the unit tests, it works, it only happens when I open the proejct a and run the unit tests.

How exactly do your settings scripts look like and what do you do to try starting those tests?

Sorry for relaying a little bit late. I am trying to crate a demo project to occur this issue.
But I can not upload files, so I will write text very detail.

Project Struct:

composite-build-example

  • app (android application project)
    • composite-build-module
      • module-a
        • src
          • test
            • ComputerTest (Unit Test file)
    • build.gradle.kts
    • settings.gradle.kts
  • build.gradle.kts
  • settings.gralde.kts

root project configuration

// settings.gradle.kts
rootProject.name = "composite-build-example"
include(":app")
includeBuild("./composite-build-module") {
    dependencySubstitution {
        substitute(
            module("com.paradisehell.composite.build:module-a")
        ).with(project(":module-a"))
    }
}

// build.grdale.kts
buildscript {
    repositories {
        mavenCentral()
        google()
        gradlePluginPortal()
    }

    dependencies {
        classpath("com.android.tools.build:gradle:4.1.3")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72")
    }
}

allprojects {
    repositories.addAll(rootProject.buildscript.repositories)
}

tasks.create<Delete>("clean") {
    delete(rootProject.buildDir)
}

composite-build-module project configuration

// settings.gradle.kts
rootProject.name = "composite-build-module"
include(":module-a")


// build.gradle.kts
buildscript {
    repositories {
        mavenCentral()
        google()
        gradlePluginPortal()
    }

    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72")
    }
}

allprojects {
    repositories.addAll(rootProject.buildscript.repositories)
}

tasks.create<Delete>("clean") {
    delete(rootProject.buildDir)
}

So when I run the test in file ComputerTest, I got this error:

Project ‘composite-build-module’ not found in root project ‘composite-build-module’.

1 Like

Project struct:

The unit test configuration:

You tell it to execute in the project composite-build-module, there the path is :module-a:test.
If you execute it in the project composite-build-example, the path would be :composite-build-module:module-a:test.

1 Like

You are right, but this is what the IDE help me to generate, I did nothing.

If I change the command in the input below Run, it will work, But if I try to click Test button, the IDE will create another unit test which with wrong configuration.

Well, I guess it is an IDE problem then.
It it happens on the latest version you should probably report it on YouTrack.

OK, I will report it.

BWT, actually in my real project, the IDE help me to generate an unit test like this one?


Do you know how to fix?

Executing tasks: [:composite-build-module:module-a:compileJava, :composite-build-module:module-a:testClasses] in project /Users/chengtao/study/test/composite-build-example/composite-build-module


Even I change working directory, it will not work.

Open the Gradle settings and change the test execution mode to delegate to Gradle.
This should be the default setting.

1 Like