Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring-boot-devtools reload of multi-module maven project changes

Reload of multi-module maven project changes


Setting

Imagine a multi-module maven-project. The project structure is:

pom.xml //parentpom
   |
  pom.xml //submodule_1
   |
  pom.xml //submodule_2
   .
   .
   .
  pom.xml //submodule_7

For example submodule_5 has submodule_6 and submodule_7 as dependencies. The submodule_5 can be build to construct a War-file which can be deployed. Spring-Boot-Devtools provide the feature of automatic-restart whenever there is a change to submodule_5 it's classpath.

Whenever the application is run using:

mvn spring-boot:run

And changes are made to submodule_5 (depending on which IDE you use the classpath get changed. (for Eclipse automaticaly / for InteliJ when pressing Ctrl+F9)) spring-boot automaticaly restarts the application and changes are added. Changes which happen to submodule_6 or submodule_7 don't trigger the automatic restart.


Questions

  1. Is there a way to make it so that whenever you make changes in submodule_6 or submodule_7 to have them force a restart and there-for apply the changes?
  2. Spring-boot-devtools uses two classloaders: "The Base Classloader" & "The Restart Classloader". Is it so that on initial start of the application submodule_6 and submodule_7 get added to "The Base Classloader" whilst submodle_5 is kept in the "The Restart Classloader"? Making it so that whenever submodule_5 forces a restart it uses the versions of submodule_6 and submodule_7 out of "The Base Classloader"?
like image 726
Nodon Darkeye Avatar asked Aug 17 '16 13:08

Nodon Darkeye


2 Answers

You may specify additional folders to be watched by spring-boot-devtools, in application.properties:

spring.devtools.restart.additional-paths=../submodule_6,../submodule_7

See Spring's documentation on using-boot-devtools-restart-additional-paths.

like image 138
alexbt Avatar answered Sep 29 '22 22:09

alexbt


To fix this problem I started running the application from within InteliJ. without having to add.

spring.devtools.restart.additional-paths=../submodule_6,../submodule_7

IntelliJ and spring-boot seem to work together very wel. The reason it was not working for me in the first place was because I was working from the commandline at first.

Difference between commandline and IDE

So spring-boot-devtools uses two classloaders to load an application. Jars will be loaded ones in the "Base classloader", your application will be loaded in the "restart classloader". This last classloader will restart everytime there is a change on the classpath.

Whenever running submodule_5 from the commandline, it will build the submodule_6 and submodule_7 and add the jars to the build of submodule_5. Whenever changes are made in submodule_6 and submodule_7 spring-boot won't even notice since it's only watching submodule_5 and has the jars it needs. Even if you would specifically tell it to also watch those submodules, it still won't rebuild those, it'll just keep using the jars it already has loaded in the "base classloader" (This is my assumption, I'm not 100% certain of the way it works).

Whenever running submodule_5 from the IDE, it won't create the jar of the submodule_6 and submodule_7. It will just use their classpath. This makes it so that changes in your intire project's classpath (all submodules) will trigger the automatic restart and the changes will be applied.

EXTRA

Whenever running from the IDE changes to resources like html-files, css-files, xml-files . . . won't trigger a restart since this is not a change in the classpath. But the changes will still be visible.

like image 31
Nodon Darkeye Avatar answered Sep 29 '22 21:09

Nodon Darkeye