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:

@file:Suppress("DSL_SCOPE_VIOLATION")

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:

Any advice?

1

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:

  1. If test-lib is also build using Gradle, you can add it to test-app as a sub-project, as described in the Gradle Documentation
  2. Alternatively, you can add test-lib's pre-compiled JAR to test-app dependencies, which Gradle also supports.
0

请先登录再写评论。