我有你的磨机Gradle web应用程序项目的基本运行,它工作正常,但我注意到Gradle的运行时类路径被包含在可能与Web应用程序冲突的jetty中.
请注意,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.
Run Code Online (Sandbox Code Playgroud)
有没有办法在运行jettyRun任务时排除gradle运行时类路径?我正在使用最新的1.0里程碑5版Gradle.
我正在寻找Ant中javac任务中'includeAntRuntime'的内容.
http://ant.apache.org/manual/Tasks/javac.html
includeAntRuntime是否在类路径中包含Ant运行时库; 默认为yes,除非设置了build.sysclasspath.通常最好将其设置为false,以便脚本的行为对运行它的环境不敏感.
剥离build.gradle:
apply plugin: 'groovy'
apply plugin: 'war'
apply plugin: 'jetty'
jettyRun {
contextPath = ''
}
Run Code Online (Sandbox Code Playgroud) JUnit5 手册中的主要WebServerExtension示例不完整,并且没有完全显示如何正确存储配置(例如,enableSecurity、服务器 url)。
该示例忽略或硬编码这些值。手册(第 5.11 节。在扩展中保持状态)暗示应该使用“Store”,但在构造对象时 ExtensionContext 尚不可用——尚不清楚如何处理将此数据作为 ExtensionContext 迁移到 Store在构造函数中尚不可用。
我还不清楚,对于 WebServerExtension 编程示例使用 Store API 是否值得,也许它可以仅使用内部状态(例如 this.serverUrl、this.enableSecurity 等)来工作。
也许商店更适用于不使用这种“编程”风格的扩展,其中可能存在(适当地)自定义扩展的多个实例?换句话说,我从指南中不清楚这是否是受支持的范例?
其他在线 JUnit 5 扩展示例(例如 org.junit.jupiter.engine.extension.TempDirectory)展示了如何利用注释来处理将配置信息传递到 Store,但如果也有像 WebServerExtension 这样的完整编程构建器类型示例,那就太好了。
像 TempDirectory 这样的示例显然可以从 beforeXXX() 方法访问 ExtensionContext,而 WebServerExtension 示例则不能。
使用下面的方法似乎工作正常,但我想确认这是一个受支持的范例(即在使用这种编程方法时使用字段而不是商店)。
public class WebServerExtension implements BeforeAllCallback {
private final boolean securityEnabled;
private final String serverUrl;
public WebServerExtension(Builder builder) {
this.securityEnabled = builder.enableSecurity;
this.serverUrl = build.serverUrl;
}
@Override
public void beforeAll(ExtensionContext context) {
// is it ok to use this.securityEnabled, this.serverUrl instead …Run Code Online (Sandbox Code Playgroud)