Hi, I’m trying to include a local jar file as a dependency, and nothing is working. First, here is the build.gradle.kt for the library:
plugins {
id("org.jetbrains.kotlin.jvm").version("1.9.20")
`java-library`
}
version = "0.1.0"
repositories {
mavenCentral()
}
dependencies {
implementation("org.apache.commons:commons-math3:3.6.1")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.0")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
withSourcesJar()
withJavadocJar()
}
tasks.named<Test>("test") {
useJUnitPlatform()
}
It exposes a single method named exampleLibraryMethod(x: Int): Int
which acts as a wrapper for an absolute value function in commons-math3. I ran the build
task and copied the 3 jar files in build/libs
into a libs
folder in a secondary project.
This secondary project has the following build.gradle.kt:
plugins {
id("org.jetbrains.kotlin.jvm").version("1.9.20")
application
}
repositories {
mavenCentral()
}
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.0")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
application {
mainClass = "org.example.AppKt"
}
tasks.named<Test>("test") {
useJUnitPlatform()
}
With this setup, I’m getting an “unresolved reference” error implying that the library is not actually being included, or it was built incorrectly. I’ve tried:
- Using
flatDir { dirs("libs") }
- Using
files("libs/mylib.jar")
Is this an issue with how I’m building the library, or with how I’m including it?