且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

启动JettyRun时排除Gradle类路径运行时

更新时间:2023-01-10 18:42:06

正如任务,它有一个 classpath 属性,默认情况下它被设置为项目。 sourceSets.main.runtimeClasspath 。您可以将此属性设置为您选择的类路径:

 配置{
myJettyRuntime
}

依赖项{
myJettyRuntimegroup:name:version
...
}

jettyRun {
classpath = .myJettyRuntime





$ b

或者,您可以从该类路径中添加或减去不需要的或冲突的依赖项,分别使用 - = + = 运算符。 $ p> jettyRun {
classpath - = configurations.myExcludedConf
}


I have your basic run of the mill Gradle web application project and it works ok but I noticed that Gradle's runtime classpath is being included in the jetty one which has the potential to conflict with the web applications.

Notice below that gradle is using a slightly older version of logback and that SL4J is warning that it found multiple bindings in the classpath.

: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.

Is there a way to exclude the gradle runtime classpath from being included when running jettyRun task? I'm using the latest 1.0 milestone 5 version of Gradle.

I'm looking for something along the lines of 'includeAntRuntime' in the javac task in Ant.

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

includeAntRuntime Whether to include the Ant run-time libraries in the classpath; defaults to yes, unless build.sysclasspath is set. It is usually best to set this to false so the script's behavior is not sensitive to the environment in which it is run.

Stripped down build.gradle:

apply plugin: 'groovy'
apply plugin: 'war'
apply plugin: 'jetty'

jettyRun {
    contextPath = ''
}

As described in the manual for jettyRun task, it has a classpath property which is by default set to project.sourceSets.main.runtimeClasspath. You can just set this property to the classpath of your choice:

configurations{
  myJettyRuntime
}

dependencies{
  myJettyRuntime "group:name:version"
  ...
}

jettyRun{
  classpath = configurations.myJettyRuntime
}

alternatively you can add or subtract unneeded or conflicting dependencies from this classpath, using -= and += operators respectively.

jettyRun{
  classpath -= configurations.myExcludedConf
}