Gradle 如何在 JavaExec 类路径中包含 runtimeOnly 依赖项?
Gradle How to include runtimeOnly dependencies in JavaExec classpath?
Gradle 如何在 JavaExec classpath 中包含 runtimeOnly 依赖项?
例如,
子项目 foo:
dependencies {
runtimeOnly files('libs/hello.jar')
}
子项目栏:
dependencies {
compile project(':foo')
}
task execHello(type: JavaExec, dependsOn: 'compileJava') {
classpath = configurations.runtime
main 'myPackage.Hello'
}
主要 class myPackage.Hello 在 libs/hello.jar 中定义,它是项目 foo 的 runtimeOnly 依赖项。
configurations.runtime 不包含 runtimeOnly 依赖项 hello.jar。如果我在项目 foo 中将 runtimeOnly 依赖项更改为 api 依赖项,它将起作用。
classpath = configurations.runtime + configuration.runtimeOnly
错误:无法明确解析 runtimeOnly。如何在 JavaExec class 路径中添加 hello.jar?
runtime
和 runtimeOnly
用于声明依赖关系。要使用依赖项,您应该根据 https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_configurations_graph.
中的文档使用配置 runtimeClasspath
Gradle 如何在 JavaExec classpath 中包含 runtimeOnly 依赖项? 例如,
子项目 foo:
dependencies {
runtimeOnly files('libs/hello.jar')
}
子项目栏:
dependencies {
compile project(':foo')
}
task execHello(type: JavaExec, dependsOn: 'compileJava') {
classpath = configurations.runtime
main 'myPackage.Hello'
}
主要 class myPackage.Hello 在 libs/hello.jar 中定义,它是项目 foo 的 runtimeOnly 依赖项。
configurations.runtime 不包含 runtimeOnly 依赖项 hello.jar。如果我在项目 foo 中将 runtimeOnly 依赖项更改为 api 依赖项,它将起作用。
classpath = configurations.runtime + configuration.runtimeOnly
错误:无法明确解析 runtimeOnly。如何在 JavaExec class 路径中添加 hello.jar?
runtime
和 runtimeOnly
用于声明依赖关系。要使用依赖项,您应该根据 https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_configurations_graph.
runtimeClasspath