I have been spinning wheels for hours trying to get a Kotlin Multi Platform project to build within a Gradle Multi Project sample.
The sample project that I have has the following structure
Where 'myKotlinMPLib' has dependency on class within 'myDependencyLib'
mac> tree.without.build
.
├── README.md
├── git.push.sh
└── simplified_top_level_project
├── build.gradle.kts
├── buildSrc
│ ├── build.gradle.kts
│ └── settings.gradle.kts
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── myDependencyLib
│ ├── README.md
│ ├── build.gradle.kts
│ ├── coverage.sh
│ ├── gradle
│ │ └── wrapper
│ │ └── gradle-wrapper.properties
│ ├── gradle.properties
│ ├── releaseToLocal.sh
│ ├── settings.gradle.kts
│ └── src
│ ├── commonMain
│ │ └── kotlin
│ │ └── com
│ │ └── asgard
│ │ └── DependencyInterface.kt
│ ├── jvmMain
│ │ └── kotlin
│ │ └── asgard
│ │ └── DependencyImplementation.kt
│ └── jvmTest
│ └── kotlin
│ └── com
│ └── asgard
│ └── TestFromDependency.kt
├── myKotlinMPLib
│ ├── README.md
│ ├── build.gradle.kts
│ ├── coverage.sh
│ ├── gradle
│ │ └── wrapper
│ │ └── gradle-wrapper.properties
│ ├── gradle.properties
│ ├── releaseToLocal.sh
│ ├── settings.gradle.kts
│ └── src
│ ├── jvmMain
│ │ └── kotlin
│ │ └── asgard
│ │ └── ConsumerImplementationDependency.kt
│ └── jvmTest
│ └── kotlin
│ └── com
│ └── asgard
│ └── ConsumerTest.kt
└── settings.gradle.kts
within 'simplified_top_level_project' I am able to run 'gradle build'
mac> pwd && gradle build
/Users/nickolaykondratyev/git_repos/glassthought-sandbox/simplified_top_level_project
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/8.1.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 4s
37 actionable tasks: 37 up-to-date
However, when I try to run gradle build
within 'myKotlinMPLib' I get an error
mac> cd myKotlinMPLib/
mac> gradle build
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/nickolaykondratyev/git_repos/glassthought-sandbox/simplified_top_level_project/myKotlinMPLib/build.gradle.kts' line: 38
* What went wrong:
Project with path ':myDependencyLib' could not be found in root project 'myKotlinMPLib'.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 362ms
To replicate locally can run the project using
git clone https://github.com/nickolay-kondratyev/glassthought-sandbox.git \
&& cd glassthought-sandbox \
&& git checkout stack-overflow-question-3 \
&& cd simplified_top_level_project \
&& echo "------------------------------------------------------" \
&& echo "At simplified_top_level_project 'gradle build' works:" \
&& gradle build \
&& echo "------------------------------------------------------" \
&& echo "However, when navigating to 'myKotlinMPLib', build does not work" \
&& cd myKotlinMPLib \
&& gradle build
Or without running full code of sample project can be found here: https://github.com/nickolay-kondratyev/glassthought-sandbox/tree/stack-overflow-question-3
Gradle thinks 'myKotlinMPLib' is a root project. How can I get individual projects to build in command line while they have dependency on libraries that are nearby and are under top level root project?