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