https://kotlinlang.org logo
Title
i

iHDeveloper

09/27/2020, 9:48 AM
I have 2 Gradle subprojects one is
core
and the other is called
other
. The
other
project has
compileOnly(project(":core"))
in the dependencies. I can code normally and I’m able to reference stuff in
core
project using the IDE (IntelliJ). But, during
compileKotlin
task for the project
other
. The compiler throws
Unresolved reference: stuff
. ☹️ It throws it for the import package from
core
project. And, the stuff I referenced in that package. It seems like the compiler didn’t include
core
project in
other
during the compilation. I tried to find an answer on the internet. But, couldn’t find what I’m looking for. I tried to clear the Gradle cache. Also, removed the
build
folder. But, both of them didn’t work What’s the issue? And, how can I solve it? 🤔
I figured out the solution to the problem. I was running the task
dependencyInsight
of
core
project in the
other project
. Output:
project :core
   variant "apiElements" [
      org.gradle.usage                    = java-api
      org.gradle.libraryelements          = jar (compatible with: classes)
      org.gradle.dependency.bundling      = external
      org.gradle.category                 = library
      org.jetbrains.kotlin.localToProject = public (not requested)
      org.jetbrains.kotlin.platform.type  = jvm
      org.gradle.jvm.version              = 8
   ]
It appears the build classes weren’t being built in the
core
project. Because, the
jar
task wasn’t enabled (because I was using the
shadowJar
). After enabling it the classes were being built. And, the
other
project was able to use the built classes. 😄