Gradle not recognizing Global Library jar
I have two projects, test-lib and test-app. The former is a Kotlin library, while the latter is a Kotlin app which depends on the former. I am in a position where I am able to add test-lib as a jar dependency to test-app, and IntelliJ recognizes this as far as syntax highlighting goes, however Gradle does not seem to recognize this, and I'm unable to get a setup like this to build.
Here is a screenshot which basically shows the issue:

The process I use for creating the library is to follow the guide detailed here: https://docs.gradle.org/current/samples/sample_building_kotlin_libraries.html. This results in a default project, for which I add a couple test functions. I then run the Gradle `build` task, which creates a jar file, "lib/build/libs/lib.jar" in my case. My library's build.gradle.kts looks like this:
plugins {
alias(libs.plugins.kotlin.jvm)
`java-library`
}
repositories {
mavenCentral()
}
dependencies {
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.9.1")
}
tasks.test {
useJUnitPlatform()
}
The process I use for adding the jar to my test-app project is to open Project Structure, go to Global Libraries, and to click the + button to select a jar file. I then select the generated lib.jar file from the above process, and IntelliJ seems to recognize this. As you can see from the screenshot, `lib` is in the "External Libraries" list, along with its code. You can also see from the code that I'm able to access a Library method as far as syntax highlighting goes. It's just when I try to actually build that I get a problem.
I have tried invalidating caches and restarting dozens of times. No dice.
I'm using:
- Windows 11 Home (10.0.22621)
- IntelliJ IDEA 2023.1.2 (Community Edition) Build #IC-231.9011.34
- Runtime version: 17.0.6+10-b829.9 amd64
- VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
- Gradle distribution URL: https://services.gradle.org/distributions/gradle-8.0-bin.zip
Any advice?
Please sign in to leave a comment.
Hello!
Your Project uses Gradle as a Build System, while Libraries (including Global Libraries) are only applicable to IDEA's native Build System.
For the scenario you have described there are two options:
test-libis also build using Gradle, you can add it totest-appas a sub-project, as described in the Gradle Documentationtest-lib's pre-compiled JAR totest-appdependencies, which Gradle also supports.