how does one include a library from another projec...
# gradle
j
how does one include a library from another project of which you have the code checked out? ProjectB's settings.gradle.kts:
Copy code
include("project-a:module-4")

project(":project-a:module-4").projectDir =
    File("../project-a/module-4")
ProjectB Module4's build.gradle.kts
Copy code
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
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
if I change
include
to
includeBuild
in
settings.gradle.kts
,
Copy code
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
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
thanks, I'll dig through those docs and figure out how to make the composite builds work
v
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
what i've tried so far is
project-b->settings.gradle.kts
Copy code
includeBuild("../project-a")
and then inside project-b's module-4
Copy code
val jvmMain by getting {
			dependencies {

				implementation("project-a:module-4")
which bombs out with
Copy code
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
Copy code
val jvmMain by getting {
			dependencies {
				implementation("io.blah:projecta-module-4")
and it works thanks for the help, much appreciated!!
v
Yes, as I said, the dependency like if the module would be deployed to maven, so basically "group:project" 🙂