在启动jetyrun时排除Gradle类路径运行时



我已经有了Gradle web应用程序项目的基本运行情况,它工作正常,但我注意到Gradle的运行时类路径被包含在jetty中,这有可能与web应用程序发生冲突。

请注意下面的gradle使用的是稍微老一点的logback版本,并且SL4J警告它在类路径中发现了多个绑定。

:jettyRun
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/dev/java/tools/gradle-1.0-milestone-5/lib/logback-classic-0.9.29.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/kirk.rasmussen/.gradle/caches/artifacts-3/ch.qos.logback/logback-classic/fd9fe39e28f1bd54eee47f04ca040f2b/jars/logback-classic-0.9.30.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

是否有一种方法可以排除gradle运行时的类路径被包括在运行jettyRun任务?我使用的是最新的1.0里程碑5版本的Gradle。

我正在寻找的东西沿着'includeAntRuntime'在javac任务在Ant.

http://ant.apache.org/manual/Tasks/javac.html

includeAntRuntime是否在类路径中包含Ant运行时库;默认为yes,除非构建。设置Sysclasspath。通常最好将其设置为false,这样脚本的行为对其运行的环境不敏感。

剥离后的build.gradle:

apply plugin: 'groovy'
apply plugin: 'war'
apply plugin: 'jetty'
jettyRun {
    contextPath = ''
}

正如jettyRun任务手册中所描述的,它有一个classpath属性,默认设置为project.sourceSets.main.runtimeClasspath。您可以将此属性设置为您选择的类路径:

configurations{
  myJettyRuntime
}
dependencies{
  myJettyRuntime "group:name:version"
  ...
}
jettyRun{
  classpath = configurations.myJettyRuntime
}

或者,您可以分别使用-=+=操作符,从这个类路径中添加或减去不需要的或冲突的依赖项。

jettyRun{
  classpath -= configurations.myExcludedConf
}

如果您只是担心两个SLF4j绑定,那么在这种情况下,您似乎可以忽略警告。

最新更新