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
This commit is contained in:
parent
d071db8cc9
commit
168fc2f61f
|
|
@ -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 <<using-spring-boot.adoc#using-boot-devtools,`devtools`>> 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]]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
<<build-tool-plugins.adoc#build-tool-plugins, Maven and Gradle plugins>> 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 <<using-spring-boot.adoc#using-boot-devtools,`spring-boot-devtools`>> module is also
|
||||
available with support for fast application restarts and LiveReload.
|
||||
|
||||
Finally, the <<build-tool-plugins.adoc#build-tool-plugins, Maven and Gradle plugins>> 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]]
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -119,15 +119,37 @@ mvn spring-boot:run
|
|||
for more details. As a convenience, the profiles to enable are handed by a specific
|
||||
property (<<<profiles>>>), see {{{./examples/run-profiles.html}Specify active profiles}}.
|
||||
|
||||
By default, any <<src/main/resources>> folder will be added to the application classpath
|
||||
when you run the application and any duplicate found in <<target/classes>> 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 <<<devtools>>>, 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:
|
||||
---
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
---
|
||||
|
||||
When <<<devtools>>> 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 <<<devtools>>>, 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:
|
||||
|
||||
---
|
||||
<build>
|
||||
|
|
@ -139,7 +161,7 @@ mvn spring-boot:run
|
|||
<artifactId>${project.artifactId}</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<configuration>
|
||||
<addResources>false</addResources>
|
||||
<addResources>true</addResources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
...
|
||||
|
|
@ -148,6 +170,17 @@ mvn spring-boot:run
|
|||
</build>
|
||||
---
|
||||
|
||||
When <<<addResources>>> is enabled, any <<src/main/resources>> folder will be added to
|
||||
the application classpath when you run the application and any duplicate found in
|
||||
<<target/classes>> 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 <<<repackage>>> goal, the <<<run>>> 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
|
||||
|
|
|
|||
Loading…
Reference in New Issue