https://kotlinlang.org logo
Title
j

janvladimirmostert

01/16/2021, 12:00 PM
how does one include a library from another project of which you have the code checked out? ProjectB's settings.gradle.kts:
include("project-a:module-4")

project(":project-a:module-4").projectDir =
    File("../project-a/module-4")
ProjectB Module4's build.gradle.kts
sourceSets {
                       val jvmMain by getting {
                           dependencies {
                               ...
                               implementation(project(":project-a:module-4"))


                           }
                       }
                   }
this compiles, but nothing resolves
it started working after a few Gradle refreshes and a clean build
v

Vampire

01/16/2021, 12:43 PM
To include a library form another project don't use
include
.
include
is for building a mutli-project build consisting of mutliple projects that belong together. To have a "sub-build" of a "foreign" dependency, use composite builds (
includeBuild
) https://docs.gradle.org/current/userguide/composite_builds.html
j

janvladimirmostert

01/16/2021, 1:11 PM
if I change
include
to
includeBuild
in
settings.gradle.kts
,
Project with path :project-a:module-4 could not be found in project :project-b:module-4
does
includeBuild
make a difference somehow? i will be working on both projectA and projectB at the same time, so if projectA changes, projectB needs to rebuild
v

Vampire

01/16/2021, 2:02 PM
Yes, that's exactly what composite builds are for. And no, you cannot simply replace the method, that's why I linked you to the docs
👍 1
j

janvladimirmostert

01/16/2021, 3:25 PM
thanks, I'll dig through those docs and figure out how to make the composite builds work
v

Vampire

01/16/2021, 4:17 PM
basically you just use
includeBuild
with the relative path to the other build (whole build, not subproject) and declare a dependency like if the project you want to depend on were in some maven repository.
you can omit the version if it is always served through the composite build
j

janvladimirmostert

01/16/2021, 4:27 PM
what i've tried so far is
project-b->settings.gradle.kts
includeBuild("../project-a")
and then inside project-b's module-4
val jvmMain by getting {
			dependencies {

				implementation("project-a:module-4")
which bombs out with
Could not find project-a:module-4:.
Required by:
    project :project-b:module-4
would be amazing if this works, can finally work concurrently on a lot of things 😄
got it working changed the dependency to
val jvmMain by getting {
			dependencies {
				implementation("io.blah:projecta-module-4")
and it works thanks for the help, much appreciated!!
v

Vampire

01/16/2021, 6:35 PM
Yes, as I said, the dependency like if the module would be deployed to maven, so basically "group:project" 🙂