Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle How to include runtimeOnly dependencies in JavaExec classpath?

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?

like image 750
eastwater Avatar asked Jul 26 '26 21:07

eastwater


1 Answers

runtime and runtimeOnly are for declaring the dependencies. To use the dependencies you should use the configuration runtimeClasspath as per the docs at https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_configurations_graph.

like image 178
Vampire Avatar answered Jul 29 '26 13:07

Vampire



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!