From 168fc2f61f0f18d8121a4da4fe15dbd06a1f1674 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 20 Oct 2015 14:29:16 +0200 Subject: [PATCH] Disable addResources by default Flip the default value of `addResources` for both the Maven and Gradle plugins. This effectively turns off static resources reloading and, more importantly, the pruning of duplicate resources from the target directory. As devetools is our mainstram solution for such feature, the documantion has been updated to reflect that. Closes gh-4227 --- .../src/main/asciidoc/build-tool-plugins.adoc | 20 ++++---- spring-boot-docs/src/main/asciidoc/howto.adoc | 11 ++-- .../boot/gradle/run/BootRunTask.java | 6 +-- .../boot/maven/AbstractRunMojo.java | 8 +-- .../src/site/apt/usage.apt.vm | 51 +++++++++++++++---- 5 files changed, 66 insertions(+), 30 deletions(-) diff --git a/spring-boot-docs/src/main/asciidoc/build-tool-plugins.adoc b/spring-boot-docs/src/main/asciidoc/build-tool-plugins.adoc index 6b74ec7bdf..1f3c9fa65a 100644 --- a/spring-boot-docs/src/main/asciidoc/build-tool-plugins.adoc +++ b/spring-boot-docs/src/main/asciidoc/build-tool-plugins.adoc @@ -310,23 +310,23 @@ To run a project in place without building a jar first you can use the "`bootRun $ gradle bootRun ---- -By default, running this way makes your static classpath resources (i.e. in -`src/main/resources` by default) reloadable in the live application, which can be helpful -at development time. Making static classpath resources reloadable means that `bootRun` -does not use the output of the `processResources` task, i.e., when invoked using -`bootRun`, your application will use the resources in their unprocessed form. - -You can disable the direct use of your static classpath resources. This will mean that -the resources are no longer reloadable but the output of the `processResources` task will -be used. To do so, set `addResources` on the `bootRun` task to `false`: +If <> has been added to your project +it will automatically monitor your application for changes. Alternatively, you can also +run the application so that your static classpath resources (i.e. in `src/main/resources` +by default) are reloadable in the live application, which can be helpful at development +time. [source,groovy,indent=0,subs="verbatim,attributes"] ---- bootRun { - addResources = false + addResources = true } ---- +Making static classpath resources reloadable means that `bootRun` does not use the output +of the `processResources` task, i.e., when invoked using `bootRun`, your application will +use the resources in their unprocessed form. + [[build-tool-plugins-gradle-global-configuration]] diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc index 2813382cb1..e1a5dc8519 100644 --- a/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -1858,15 +1858,16 @@ requests). To switch that on in a Spring Boot application you just need to set === Reload static content There are several options for hot reloading. Running in an IDE (especially with debugging on) is a good way to do development (all modern IDEs allow reloading of static resources -and usually also hot-swapping of Java class changes). The -<> also -support running from the command line with reloading of static files. You can use that -with an external css/js compiler process if you are writing that code with higher level -tools. +and usually also hot-swapping of Java class changes). The <> module is also available with support for fast application restarts and LiveReload. +Finally, the <> can +be configured to support running from the command line with reloading of static files. You +can use that with an external css/js compiler process if you are writing that code with +higher level tools. + [[howto-reload-thymeleaf-template-content]] diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/run/BootRunTask.java b/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/run/BootRunTask.java index 23b7bd70ef..64a37814c7 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/run/BootRunTask.java +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/run/BootRunTask.java @@ -38,12 +38,12 @@ public class BootRunTask extends JavaExec { /** * Whether or not resources (typically in {@code src/main/resources} are added - * directly to the classpath. When enabled (the default), this allows live in-place - * editing of resources. Duplicate resources are removed from the resource output + * directly to the classpath. When enabled, this allows live in-place editing + * of resources. Duplicate resources are removed from the resource output * directory to prevent them from appearing twice if * {@code ClassLoader.getResources()} is called. */ - private boolean addResources = true; + private boolean addResources = false; public boolean getAddResources() { return this.addResources; diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java index 1bc5532282..5b70a85510 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java +++ b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java @@ -64,11 +64,13 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo { /** * Add maven resources to the classpath directly, this allows live in-place editing of * resources. Duplicate resources are removed from {@code target/classes} to prevent - * them to appear twice if {@code ClassLoader.getResources()} is called. + * them to appear twice if {@code ClassLoader.getResources()} is called. Please consider + * adding {@code spring-boot-devtools} to your project instead as it provides this feature + * and many more. * @since 1.0 */ - @Parameter(property = "run.addResources", defaultValue = "true") - private boolean addResources; + @Parameter(property = "run.addResources", defaultValue = "false") + private boolean addResources = false; /** * Path to agent jar. NOTE: the use of agents means that processes will be started by diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/usage.apt.vm b/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/usage.apt.vm index 162b5f418d..81d25541a9 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/usage.apt.vm +++ b/spring-boot-tools/spring-boot-maven-plugin/src/site/apt/usage.apt.vm @@ -119,15 +119,37 @@ mvn spring-boot:run for more details. As a convenience, the profiles to enable are handed by a specific property (<<>>), see {{{./examples/run-profiles.html}Specify active profiles}}. - By default, any <> folder will be added to the application classpath - when you run the application and any duplicate found in <> will be - removed. This allows hot refreshing of resources which can be very useful when developing - web applications. For example, you can work on HTML, CSS or JavaScipt files and see your - changes immediately without recompiling your application. It is also a helpful way of - allowing your front end developers to work without needing to download and install a Java IDE. + Spring Boot 1.3 has introduced <<>>, a module to improve the development-time + experience when working on Spring Boot applications. To enable it, just add the following + dependency to your project: - Of course, if your resources are using tokens that are filtered by Maven, you may want - to disable that feature as follows: +--- + + + org.springframework.boot + spring-boot-devtools + ${project.version} + true + + +--- + + When <<>> is running, it detects change when you recompile your application and + automatically refreshes it. This not only work for resources but code as well. It also + provides a LiveReload server so that it can automatically trigger a browser refresh whenever + things change. + + Devtools can also be configured to only refresh the browser whenever a static resource has + changed (and ignore any change in the code). Just include the following property in your + project: + +--- +spring.devtools.remote.restart.enabled=false +--- + + Prior to <<>>, the plugin supported hot refreshing of resources by default which has + now be disabled in favor of the solution desribed above. You can restore it at any time by + configuring your project: --- @@ -139,7 +161,7 @@ mvn spring-boot:run ${project.artifactId} ${project.version} - false + true ... @@ -148,6 +170,17 @@ mvn spring-boot:run --- + When <<>> is enabled, any <> folder will be added to + the application classpath when you run the application and any duplicate found in + <> will be removed. This allows hot refreshing of resources which can be very + useful when developing web applications. For example, you can work on HTML, CSS or JavaScipt + files and see your changes immediately without recompiling your application. It is also a helpful + way of allowing your front end developers to work without needing to download and install a Java + IDE. + + Note that a side effect of using this feature is that filtering of resources at build time will + not work. + In order to be consistent with the <<>> goal, the <<>> goal builds the classpath in such a way that any dependency that is excluded in the plugin's configuration gets excluded from the classpath as well. See {{{./examples/exclude-dependency.html}Exclude a dependency}} for