目前,我正在制作一个库,并尝试将其导入到我们的项目中。该库包含诸如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"))))
}我怎么才能做我想做的事?我一定要做肥罐子吗?
发布于 2021-09-23 06:54:31
我看到您正在使用spring boot,所以最直接的方法是使用Spring Boot Gradle Plugin,当在项目中配置它时,您可以运行任务bootJar,然后就会创建一个完整的spring boot jar。
https://stackoverflow.com/questions/69295171
复制相似问题