44

I was reading around a lot about spring dev tools and I have tried them on and they seem pretty cool. However, I don't understand how they get enabled / disabled. For instance just adding the dependency, everything magically works, but what if I wanted to deploy my code to production? Are the dev tools still running and I need to disable them with a profile or something?

Matthew Fontana
  • 3,790
  • 2
  • 30
  • 50
  • Just by adding a dependency, they will be on the classpath when you run the app so that Spring Boot will find them and activate them. For production, make sure you don't include the devtools jar file(s) in the classpath; or in your build, use for example Maven profiles and make sure the devtools are not included as a dependency for the production build. – Jesper Jun 08 '16 at 11:47
  • Ok so I should add the dependency to a developer profile or something like that enable it or disable it. Is there an alternative option of using an environment variable to configure it or does it have to be a profile? – Matthew Fontana Jun 08 '16 at 12:22

4 Answers4

60

No, it's turned off automatically.

From the Spring Boot reference documentation:

Developer tools are automatically disabled when running a fully packaged application. If your application is launched using java -jar or if it’s started using a special classloader, then it is considered a “production application”. Flagging the dependency as optional is a best practice that prevents devtools from being transitively applied to other modules using your project. Gradle does not support optional dependencies out-of-the-box so you may want to have a look to the propdeps-plugin in the meantime.

and

If you want to ensure that devtools is never included in a production build, you can use the excludeDevtools build property to completely remove the JAR. The property is supported with both the Maven and Gradle plugins.

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176
  • 1
    Awesome thank you very much Brian I was having a hard time finding this. Is there a documentation link for these so I can read more? – Matthew Fontana Jun 08 '16 at 12:48
  • 2
    Yes, it's already available as a link in my answer: http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html#using-boot-devtools The reference guide is well, the reference when it comes to Boot features :-) – Brian Clozel Jun 08 '16 at 12:49
  • Here's another stackoverflow answer with some more detail: https://stackoverflow.com/questions/42759587/intellij-spring-dev-tools-remote-docker-error-unexpected-404-response-uploadi/47425443#47425443 – tunesmith Nov 22 '17 at 01:31
22

It is excluded automatically for Spring Boot applications that use the JAR packaging. However, for WAR packaged Spring Boot projects, it is not. For Maven Spring Boot projects you must mark the dependency as provided and also set excludeDevTools=true in your pom.xml.

Change devtools to "provided"

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>provided</scope>
</dependency>

Exclude devtools from maven spring build plugin

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <excludeDevtools>true</excludeDevtools>
    </configuration>
</plugin>

More information here: https://github.com/spring-projects/spring-boot/issues/7556

Paolo
  • 20,112
  • 21
  • 72
  • 113
Burton
  • 821
  • 8
  • 16
  • 2
    The `excludeDevtools` setting is `true` [by default](https://docs.spring.io/spring-boot/docs/current/maven-plugin/repackage-mojo.html#excludeDevtools). – rustyx Nov 09 '18 at 08:26
  • 2
    You are correct, but when packaging a WAR it is included unless specifically excluded regardless of the default value. https://github.com/spring-projects/spring-boot/issues/7556 – Burton Nov 10 '18 at 14:48
1

spring-boot-devtools is only for easing development effort. While packaging the application this dependency is not included. Cannot be used to create a shippable product.

Ray
  • 11
  • 1
-1

I propose to use maven profiles and exclude it altogether in production environment.

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
Kuppusamy
  • 65
  • 1
  • 6
  • The question is about turning off in production and as it is a library to assist development, i would prefer to exclude it altogether from final artefact using maven profile.. – Kuppusamy Oct 27 '22 at 21:47