Paul Blundell
03/18/2022, 11:48 AMproject.configurations.maybeCreate("implementation")
project.dependencies.add("implementation", project(":my:nested:child:project"))
I’m trying to create a unit test that creates a multi-project build that tests this.
But I can’t seem to create a child project, that will end up with the coordinates ":my:nested:child:project"
?
For example in a unit test this code here:
val subDir = File(rootProject.projectDir, "my/nested/child/project").also { it.mkdirs() }
val child = ProjectBuilder.builder()
.withProjectDir(subDir)
.withName("example-project")
.withParent(rootProject)
.build()
When I log out the child project in my plugin, it tells me the path is:
:example-project
if I change withName
to:
.withName("my:nested:child:project")
I get the error:
The project name ‘mynestedchild:project’ must not contain any of the following characters: [/, \, :, <, >, “, ?, *, |]. Set the ‘rootProject.name’ or adjust the ‘include’ statement.What I am I missing so that I can use the coordinates
":my:nested:child:project"
to reference my sub project? (So that my coordinates are the same as a typical build.gradle
reference implementation project(":my:nested:child:project")
.)CristianGM
03/18/2022, 12:20 PMCristianGM
03/18/2022, 12:22 PMCristianGM
03/18/2022, 12:36 PMCristianGM
03/18/2022, 12:41 PMclass Test {
@get:Rule
val testProjectDir = TemporaryFolder()
@Test
fun test() {
val subDir = File(testProjectDir.root, "my/nested/child/project").also { it.mkdirs() }
val rootProject = ProjectBuilder.builder().withProjectDir(testProjectDir.root).build()
val my = ProjectBuilder.builder()
.withProjectDir(File(testProjectDir.root, "my"))
.withName("my")
.withParent(rootProject)
.build()
val child = ProjectBuilder.builder()
.withProjectDir(subDir)
.withName("example-project")
.withParent(my)
.build()
println(child.path)
}
}
CristianGM
03/18/2022, 12:41 PMPaul Blundell
03/18/2022, 1:06 PMVampire
03/18/2022, 1:28 PMa:b:c
, then you effectively create three projects that happen to also live in the respective directory structure by default. But you can also include foo
and set its project directory to a/b/c
.Paul Blundell
03/18/2022, 2:27 PMVampire
03/18/2022, 2:28 PMPaul Blundell
03/18/2022, 2:31 PMVampire
03/18/2022, 2:31 PMinclude("a:b:c")
in the settings script it is the same as doing include("a"); include("a:b"); include("a:b:c")
.
You are registering three projects a
, b
, and c
that happen to live in a/
, a/b/
, and a/b/c
.
There is no project with name my:nested:child:project
.
There is a project with name project
that is the child of the project child
which is the child of the project nested
which is the child of the project my
.
Imagine the task graph like a filesystem where :
is the path separator.Paul Blundell
03/18/2022, 2:32 PMVampire
03/18/2022, 2:33 PMinclude("c")
and then set the project directory of that project to be a/b/c
.
The directories don't "have to be own projects", that just the conventional default.Vampire
03/18/2022, 2:34 PMOk, so in the original question I am trying to recreate the gradle project structure. Therefore making each of the path segments a project sounds right?Definitely, Cristian was totally right. Just wanted to clarify on "all directories need to be own projects"
Paul Blundell
03/18/2022, 2:34 PMVampire
03/18/2022, 2:34 PMPaul Blundell
03/18/2022, 2:35 PMVampire
03/18/2022, 2:36 PMsubprojects { ... }
or allprojects { ... }
blocks,
so in some projects the whole build logic was just in the root project, so no build scripts needed for the individual projects.Vampire
03/18/2022, 2:36 PM