Ask Your Question

Can a transitive dependency in gradle be made exclusively for runtime purposes?

asked 2022-02-04 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-11-21 13:00:00 +0000

ladyg gravatar image

Yes, a transitive dependency in Gradle can be marked as "runtimeOnly" which means that the dependency will only be included at runtime and not during compile time. This allows you to reduce the size of your compiled JAR or WAR file according to your project's requirements.

For example, you can mark a dependency as runtimeOnly in your Gradle build script by adding the following code to the dependencies block:

dependencies {
   // compile time dependencies
   implementation 'com.sample:dependency1:1.0'

   // runtime dependencies
   runtimeOnly 'com.sample:dependency2:2.0'

In this example, "dependency1" will be included during both compile time and runtime, but "dependency2" will only be included at runtime.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer

Question Tools


Asked: 2022-02-04 11:00:00 +0000

Seen: 19 times

Last updated: Nov 21 '22