Gradle - projects with same folder but different paths

Viewed 24

I know you can't include projects with the same name, that makes sense, but why does following not work:

include(":app:core")
include(":library1:core")
include(":library2:core")

I want the folding feature of the IDE that this approach brings as a side effect, but because all 3 projects end on "core" this fails when building the project.

Can this problem be solved OTHER than following:

include(":app-core")
project(":app-core").projectDir = file("app/core")
include(":library1-core")
project(":library1-core").projectDir = file("library1/core")
include(":library2-core")
project(":library2-core").projectDir = file("library2/core")

Using "-" or "." as separator does solve the compiling issue but then the IDE does not fold the projects anymore...

I really like to use the ":" style inside my open source libraries but when I want to include them in an app I get problems because more than one of my libraries has a core module...

Question

I wonder if there is some setting or other trick to get the folding inside the IDE and have the ability to have multiple core modules inside a project but in different paths and use those 2 features together.

1 Answers

What is the build failure that you see?

I'm successfully using a multiproject build that has multiple subprojects with the same project name under different paths. The only change I had to make was this:

allprojects {
    extensions.findByType<BasePluginExtension>()?.apply {
        archivesName.set("myproject" + path.replace(":", "-"))
    }
}

I did it for allprojects in the root build.gradle.kts, but you could also do it individually for each affected project.

This ensures that each library gets a unique filename for the .jar containing its classes.

Without the change, :library1:core and :library2:core would both end up being built as core.jar and would conflict at runtime. After the change, I get myproject-library1-core.jar and myproject-library2-core.jar, and everything works fine.

Related