Gradle How to include runtimeOnly dependencies in JavaExec classpath? For example,
subproject foo:
dependencies {
runtimeOnly files('libs/hello.jar')
}
subproject bar:
dependencies {
compile project(':foo')
}
task execHello(type: JavaExec, dependsOn: 'compileJava') {
classpath = configurations.runtime
main 'myPackage.Hello'
}
the main class myPackage.Hello is defined in the libs/hello.jar that is a runtimeOnly dependency for project foo.
configurations.runtime does not contain the runtimeOnly dependency hello.jar. If I changed the runtimeOnly dependency as api dependency in project foo, it will work.
classpath = configurations.runtime + configuration.runtimeOnly
Error: runtimeOnly can not be explicitly resolved. How to add the hello.jar in the JavaExec classpath?
runtime
andruntimeOnly
are for declaring the dependencies. To use the dependencies you should use the configurationruntimeClasspath
as per the docs at https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_configurations_graph.