14

I am puzzled by this block of code to be used in a gradle file, suggested by Spring Boot Documentation on Developer Tools

configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
}
dependencies {
    developmentOnly("org.springframework.boot:spring-boot-devtools")
}

I think I must declare the developmentOnly configuration because it is to be used in the dependencies {} block, but why do I need the lines for runtimeClasspath? I actually tried removing the lines in my project and the project built prefectly fine.

configurations {
    developmentOnly
}
dependencies {
    developmentOnly("org.springframework.boot:spring-boot-devtools")
}

Is runtimeClasspath used by the Java Plugin? (As suggested by this doc) Will there be any bad side-effect if I do not include those lines for runtimeClasspath?

Update (2019-12-10)

I can also confirm that the built executable jar built without the runtimeClasspath directive ran prefectly okay. So I really don't know what that directive is doing.

leeyuiwah
  • 6,562
  • 8
  • 41
  • 71
  • 2
    You can read more about it in the original issue that sparked this change: https://github.com/spring-projects/spring-boot/issues/14451 – Cisco Dec 10 '19 at 03:10
  • @FranciscoMateo, Thanks for the pointer. I have read the issue discussion but still don't quite understand it. It seems `runtimeClasspath` is somehow used by someone, but I don't know how and who. I have already re-read the documentation on the Java Plugin -- to no avail. https://docs.gradle.org/current/userguide/building_java_projects.html – leeyuiwah Dec 10 '19 at 13:23

2 Answers2

6

You need spring-boot-devtools only at runtime, that's why we're using runtimeClasspath config.

more details: https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_configurations_graph

julz256
  • 2,222
  • 1
  • 15
  • 12
Punj
  • 151
  • 2
  • 5
1
  • The developmentOnly is a new configuration that you add.
  • The runtimeClasspath configuration is added by the Java Library Plugin.
  • You specify that the runtimeClasspath configuration extend from your developmentOnly configuration.
  • You set spring-boot-devtools as a dependency for your developmentOnly configuration, which will make the runtimeClasspath depend on spring-boot-devtools too.

I actually tried removing the lines in my project and the project built prefectly fine.

I think this is because the dependency is for run time, not for build time.

I can also confirm that the built executable jar built without the runtimeClasspath directive ran prefectly okay.

I think this is because spring-boot-devtools only works on development mode, e.g. when you execute the bootRun task with ./gradlew bootRun.

clapas
  • 1,768
  • 3
  • 16
  • 29