我必须为我的库建立一个胖罐吗?



目前,我正在制作一个库并尝试将其导入到我们的项目中。该库包含Exposed.

等库。下面的代码是库的build.gradle.kts

plugins {
kotlin("jvm")
}
val exposedVersion: String by project
dependencies {
implementation(kotlin("stdlib"))
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("test"))
implementation(kotlin("test-junit"))
implementation(kotlin("reflect"))
implementation(kotlin("script-runtime"))
implementation(kotlin("script-util"))
implementation(kotlin("scripting-jsr223"))
implementation("org.slf4j", "slf4j-api", "1.7.30")
implementation("org.jetbrains.exposed:exposed-core:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-dao:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-jdbc:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-java-time:$exposedVersion")
}

但是,当构建JAR并将其添加到项目中时,它会抛出一个错误(NoClassDefFoundError),它无法找到JAR引用的类,例如Exposed。

由于上面的错误,就像下面的代码一样,我不得不把我从库中添加的所有库添加回项目中。

val exposedVersion: String by project
dependencies {
// spring
implementation("org.springframework.boot:spring-boot-starter")

/** other dependencies */
// Dependencies for `my library jar`
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation(kotlin("script-runtime"))
implementation(kotlin("scripting-jsr223"))
implementation("org.jetbrains.exposed:exposed-core:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-dao:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-jdbc:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-java-time:$exposedVersion")
}

我想要的build.gradle.kts如下。

val exposedVersion: String by project
dependencies {
// spring
implementation("org.springframework.boot:spring-boot-starter")

/** other dependencies */
// Dependencies for `my library jar`
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
}

我怎样才能做我想做的?我一定要做肥罐吗?

我看到你正在使用spring boot,所以最直接的方法是使用spring boot Gradle Plugin,当它在你的项目中配置时,你运行任务bootJar,一个胖的spring boot jar将被创建。

最新更新