Can I include the same project into two included b...
# gradle
n
Can I include the same project into two included builds (in a complex Kotlin Multiplatform project) and use this setup in Idea? Something like:
Copy code
root
|- shared
|- project1
|- project2
and
Copy code
// in root's settings.gradle.kts

includeBuild("shared")
includeBuild("project1")
includeBuild("project2")

// in project1's settings.gradle.kts

includeBuild("../shared")

// in project2's settings.gradle.kts

includeBuild("../shared")
Thanks.
not kotlin but kotlin colored 1
c
No, you can't:
β€’ Multiple composite builds may conflict when run in parallel, if more than one includes the same build. Gradle does not share the project lock of a shared composite build to between Gradle invocation to prevent concurrent execution.
https://docs.gradle.org/current/userguide/composite_builds.html#current_limitations_and_future_work
😞 1
πŸ™ 1
v
"may conflict when run in parallel"
So yes you can just fine, just make sure to not run those projects in parallel
That means, make sure to not build
project1
in one console and
proejct2
in another console at the same time
As long as you keep an eye on that, all is fine with that setup
πŸ™ 1
n
not build
project1
in one console and
proejct2
in another console at the same time
Hm, I'm curious whether Idea takes it into account when building the root project...
v
That shouln't be a problem, as in that case, it is one composite build. Only if you execute separate builds that include the same project on disk it might lead to problems.
Btw. of course the obligatory: Please look at the channel topic to find that your question is off-topic πŸ˜‰
n
Please look at the channel topic to find that your question is off-topic πŸ˜‰
I was specifically interested in multi-module Kotlin Multiplatform project behaviour. Mainly because there were lots of issues with KMP and included builds in the past years. I didn't know at the start of the discussion that this is a core Gradle limitation... πŸ˜…
v
Ah, ok, then probably an edge-case. πŸ˜„ There I cannot say much, as I'm not using KMP. So take my statements only regarding core Gradle.
πŸ™ 1
πŸ€— 1
πŸ™‚ 1
c
Hm, I'm curious whether Idea takes it into account when building the root project...
It does not.
πŸ™ 1
v
It does not what?
c
just make sure to not run those projects in parallel
it will also happen when you execute any command that requires to compile both projects with
--parallel
enabled (which is the default nowadays), for example
./gradlew check
It does not what?
If you start multiple run configurations, IDEA will start multiple Gradle daemons to satisfy them, in parallel.
v
If you start those on the different projects, it is the same problem, yes. If you start through the composite
root
build I'd expect it to work properly.
--parallel
is not the default
And never will be the default
It will be removed in favor of configuration cache which can run all tasks in parallel, not only tasks of different projects like
--parallel
c
The configuration cache does not run tasks, do you mean the build cache? But even that doesn't run tasks in parallel without
--parallel
.
v
No, I meant configuration cache
It does not run tasks, but if used, it enables all tasks to run in parallel if they don't have a dependency on each other even within one project.
c
Is that documented anywhere? It's the first time I've head of the configuration cache having any impact on task execution. To my knowledge, it only impacted the configuration phase.
v
--parallel
just enables running tasks of different projects if they are decoupled and is completely independent
[...]
However, you should see build performance improvement immediately because tasks will run in parallel.
[...]
β€’ All tasks run in parallel by default, subject to dependency constraints.
Was always like that with configuration cache. It is one of its main goals. 1. to skip the configuration phase if possible 2. to run all tasks in parallel
πŸ‘ 1
c
Thanks, I missed that part. Very good to know.
πŸ‘Œ 1