我有一个 Gradle 项目,作为一个简单的示例,它看起来与此类似:
root
|
|build.gradle.kts
|settings.gradle.kts
|config.yaml
|web/
|build.gradle.kts
|src/
|main/
|java....(etc)
该 Web 项目是一个准系统 Dropwizard 应用程序,除了声明配置和使用该配置的应用程序以便服务器可以启动之外什么也不做。
在我的 root
路径中,我已在 settings.gradle.kts
文件中定义了我的子项目(在本例中为 :web
)。在我的 root
build.gradle.kts
中,我声明了一个 implementation(project(":web"))
依赖项。
我有一个 run
任务和一个 fatJar
任务来运行/构建此应用程序。
val run by tasks.getting(JavaExec::class) {
args("server", "config.yaml")
}
val fatJar = task("fatJar", type = Jar::class) {
manifest {
attributes["Implementation-Title"] = "Some API"
attributes["Main-Class"] = "my.package.web.HelloWorldApplication"
}
from(configurations.runtimeClasspath.get().map({ if (it.isDirectory) it else zipTree(it) }))
with(tasks.jar.get() as CopySpec)
}
tasks {
"build" {
dependsOn(fatJar)
}
}
我可以构建 fatJar,它包含我期望的所有类(根依赖项、Web 依赖项、它们的传递依赖项等)。
但是,当我运行 ./gradlew run
时,由于在类路径上发现了多个日志记录绑定(bind),我在启动 Dropwizard 应用程序时遇到错误。错误如下:
./gradlew run
Starting a Gradle Daemon, 1 busy and 1 incompatible and 3 stopped Daemons could not be reused, use --status for details
> Task :run
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/me/.gradle/caches/5.4.1/generated-gradle-jars/gradle-api-5.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/me/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.3/7c4f3c474fb2c041d8028740440937705ebb473a/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.gradle.internal.logging.slf4j.OutputEventListenerBackedLoggerContext]
Exception in thread "main" java.lang.IllegalStateException: Unable to acquire the logger context
at io.dropwizard.logging.LoggingUtil.getLoggerContext(LoggingUtil.java:46)
at io.dropwizard.logging.BootstrapLogging.bootstrap(BootstrapLogging.java:52)
at io.dropwizard.logging.BootstrapLogging.bootstrap(BootstrapLogging.java:41)
at io.dropwizard.Application.bootstrapLogging(Application.java:38)
at io.dropwizard.Application.<init>(Application.java:26)
at my.package.web.HelloWorldApplication.<init>(HelloWorldApplication.java:15)
at my.package.web.HelloWorldApplication.main(HelloWorldApplication.java:17)
> Task :run FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':run'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 25s
13 actionable tasks: 1 executed, 12 up-to-date
我知道我可以从 Dropwizard 中删除 logback,但我真的更想弄清楚为什么 gradle-api-5.4.1.jar
被捆绑到我的应用程序中。我一辈子都无法弄清楚,也不明白为什么它会被拉进去。
任何方向将不胜感激。
谢谢
最佳答案
因此,我在提出这个问题和所做的事情时所犯的错误是,我没有提及或意识到我在我的根脚本中意外应用了 kotlin-dsl 插件。一旦我删除了它,一切都按我的预期进行。
关于java - 用于具有子项目的项目的 Dropwizard + Gradle fatJar 引入 gradle-api-5.4.1.jar deps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56488566/