├── .github └── workflows │ └── ci.yml ├── .gitignore ├── LICENSE ├── README.md ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── plugin ├── build.gradle.kts ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ ├── main │ └── kotlin │ │ └── io │ │ └── reflectoring │ │ └── devtools │ │ ├── DevToolsPlugin.kt │ │ └── DevToolsPluginDsl.kt │ └── test │ └── kotlin │ └── io │ └── reflectoring │ └── devtools │ ├── BuildTaskAssert.kt │ ├── Files.kt │ ├── MultiModuleTests.kt │ ├── SingleModuleTests.kt │ ├── SourceFile.kt │ └── TargetFile.kt └── samples ├── multi-module ├── README.md ├── app │ ├── custom-configuration.gradle │ ├── default-configuration.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── io │ │ │ └── reflectoring │ │ │ └── app │ │ │ ├── DevtoolsDemoApplication.java │ │ │ └── HelloController.java │ │ └── resources │ │ ├── META-INF │ │ └── spring-devtools.properties │ │ └── application.yml ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── module1 │ ├── build.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── io │ │ │ └── reflectoring │ │ │ └── module1 │ │ │ ├── Module1Configuration.java │ │ │ └── Module1Controller.java │ │ └── resources │ │ ├── META-INF │ │ └── spring.factories │ │ └── static │ │ └── github.png ├── module2 │ ├── build.gradle │ └── src │ │ └── main │ │ ├── java │ │ └── io │ │ │ └── reflectoring │ │ │ └── module2 │ │ │ ├── Module2Configuration.java │ │ │ └── Module2Controller.java │ │ └── resources │ │ └── META-INF │ │ └── spring.factories └── settings.gradle └── single-module ├── .gitignore ├── README.md ├── custom-trigger-file.gradle ├── default-configuration.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main ├── java │ └── io │ │ └── reflectoring │ │ └── springbootdevtools │ │ └── samples │ │ └── singlemodule │ │ ├── HelloController.java │ │ └── SingleModuleApplication.java └── resources │ ├── application.yml │ ├── static │ └── hello.css │ └── templates │ └── hello.html └── test └── java └── io └── reflectoring └── springbootdevtools └── samples └── singlemodule └── SingleModuleApplicationTests.java /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | 10 | - name: "Checkout sources" 11 | uses: actions/checkout@v1 12 | 13 | - name: "Setup Java" 14 | uses: actions/setup-java@v1 15 | with: 16 | java-version: 13 17 | 18 | - name: "Run Gradle build" 19 | run: | 20 | cd plugin 21 | chmod 755 gradlew 22 | ./gradlew build -Dci=true 23 | 24 | - name: "Zip build reports" 25 | if: failure() 26 | run: zip -r reports.zip **/build/reports 27 | 28 | - name: "Upload build reports" 29 | uses: actions/upload-artifact@v1 30 | if: failure() 31 | with: 32 | name: reports 33 | path: reports.zip 34 | 35 | - name: "Set PLUGIN_VERSION environment variable" 36 | run: | 37 | cd plugin 38 | echo "::set-env name=PLUGIN_VERSION::$(./gradlew --quiet printVersion)" 39 | 40 | - name: "Publish to Gradle Plugin Portal" 41 | if: github.ref == 'refs/heads/release' 42 | run: | 43 | cd plugin 44 | ./gradlew publishPlugins -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} 45 | 46 | - name: Create Release 47 | if: github.ref == 'refs/heads/release' 48 | id: create_release 49 | uses: actions/create-release@v1 50 | env: 51 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token 52 | with: 53 | tag_name: ${{ env.PLUGIN_VERSION }} 54 | release_name: Release ${{ env.PLUGIN_VERSION }} 55 | body: 56 | draft: false 57 | prerelease: false 58 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/build 2 | **/.gradle 3 | **/.idea 4 | /samples/single-module/build.gradle 5 | /samples/multi-module/app/build.gradle 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Tom Hombergs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Dev Tools Gradle Plugin 2 | 3 | ![CI](https://github.com/thombergs/spring-devtools-gradle-plugin/workflows/CI/badge.svg) 4 | [![GitHub release](https://img.shields.io/github/release/thombergs/spring-boot-devtools-gradle-plugin.svg)](https://plugins.gradle.org/plugin/io.reflectoring.spring-boot-devtools) 5 | 6 | This plugin enables [Spring Boot Dev Tools](https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-devtools) in your Gradle-based project to improve the dev loop when working on your Spring Boot application. 7 | 8 | This plugin brings the following tasks: 9 | 10 | * `./gradlew restart` to trigger a restart of the Spring application context when you have changed a Java file 11 | * `./gradlew reload` to trigger a refresh of static resources when you have changed HTML templates, images, or other static resources 12 | 13 | Run these tasks while you have started a Spring Boot application via `./gradlew bootrun` and the changes you made will become visible in the application after a couple seconds. A reload is quicker than a restart because it doesn't need to restart the Spring application context. 14 | 15 | If you want a more in-depth explanation about what Spring Boot Dev Tools does to appreciate what this Gradle plugin is doing for you, have a look at the article [Optimize Your Dev Loop with Spring Boot Dev Tools](https://reflectoring.io/spring-boot-dev-tools/). 16 | 17 | ## Configuration 18 | 19 | ### Apply the plugin 20 | 21 | Apply the plugin to the Gradle module containing the Spring Boot application: 22 | 23 | ```groovy 24 | plugins { 25 | id 'org.springframework.boot' version '2.3.2.RELEASE' 26 | id 'io.spring.dependency-management' version '1.0.9.RELEASE' 27 | id 'java' 28 | id 'io.reflectoring.spring-boot-devtools' version '0.0.2' // <--- 29 | } 30 | ``` 31 | 32 | ### Configure a trigger file 33 | 34 | Add this to your `application.yml`: 35 | 36 | ```yaml 37 | devtools: 38 | restart: 39 | trigger-file: .triggerFile 40 | additional-paths: build 41 | ``` 42 | 43 | This configures Spring Boot Dev Tools to only restart the Spring Boot app when the file `/build/.triggerFile` changes. This file is touched by the plugin each time it has updated all the changed files. 44 | 45 | ### Configure contributing modules 46 | 47 | If you want to see changes in contributing modules (i.e. Gradle modules that contribute a JAR file to the Spring Boot application), you have to declare if you want them to be included in a restart and a reload by adding them to the `restart` and/or `reload` configuration: 48 | 49 | ```groovy 50 | dependencies { 51 | 52 | // these modules contribute a JAR file to the Spring Boot app 53 | implementation project(':module1') 54 | implementation project(':module2') 55 | 56 | // this enables auto-restart for changes in module1 57 | restart project(':module1') 58 | 59 | // this enables auto-reload for changes in module2 60 | reload project(':module2') 61 | 62 | // Spring Boot dependencies and other dependencies omitted 63 | } 64 | ``` 65 | 66 | Running `./gradlew restart` will now copy all compiled Java files into the `build/classes` folder of the Spring Boot module to refresh the classpath and trigger a restart. 67 | 68 | Running `./gradlew reload` will now copy all files from `src/main/resources` from the module into the `build/resources` folder of the Spring Boot module to refresh the classpath and trigger a reload. 69 | 70 | If a module contributes resource files from a different location than `src/main/resources`, you can specify a custom Gradle task to be called on `restart` for each module: 71 | 72 | ```groovy 73 | devtools { 74 | 75 | modules { 76 | // "module1" is a random, but unique, identifier for 77 | // the module we're configuring. 78 | module1 { 79 | 80 | // Must be one of the modules in the restart configuration. 81 | dependency = ":module1" 82 | 83 | // This task will be called every time `./gradlew reload` is called. 84 | // It's expected to all changed resources into the folder "build/resources/main". From there, they 85 | // will automatically be copied to the main module. Alternatively, this task can copy any changed files 86 | // directly into the "build/resources/main" folder of the main module. 87 | reloadTask = "reload" 88 | 89 | } 90 | } 91 | } 92 | ``` 93 | 94 | ### Configure a custom trigger file 95 | 96 | If the default trigger file `.triggerFile` does not suit you, you can change to name othe trigger file: 97 | 98 | ```groovy 99 | devtools { 100 | // Change the name of the trigger file. The plugin creates this file in the "build" folder of the 101 | // main module after each call of the "restart" task. Make sure to configure the same trigger file 102 | // in devtools.restart.trigger-file in your application.yml or application.properties file. 103 | triggerFile = ".triggerFile" 104 | } 105 | ``` 106 | 107 | ## Samples 108 | 109 | Look at the sample projects to see the plugin in action: 110 | 111 | * [single-module](samples/single-module) 112 | * [multi-module](samples/multi-module) 113 | 114 | ## Limitations 115 | 116 | The plugin has been tested with single- and multi-module Gradle builds in a pretty standard configuration that should cover the most common cases. The plugin has also been successfully tested with NPM projects (wrapped in Gradle) that provide Javascript resources to a Spring Boot application. 117 | 118 | The plugin currently works with these assumptions: 119 | 120 | * the contributing modules have the `java` plugin installed 121 | * the contributing modules produce a single JAR file in `build/libs` 122 | * the build folder of the modules is `build` 123 | * ... and probably a bunch of other assumptions that I haven't identified, yet. 124 | 125 | Feel free to open issues with feature requests or pull requests with improvements! -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thombergs/spring-boot-devtools-gradle-plugin/b71827164792eefe93864cf2ddb99c752991a689/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | 88 | @rem Execute Gradle 89 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 90 | 91 | :end 92 | @rem End local scope for the variables with windows NT shell 93 | if "%ERRORLEVEL%"=="0" goto mainEnd 94 | 95 | :fail 96 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 97 | rem the _cmd.exe /c_ return code! 98 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 99 | exit /b 1 100 | 101 | :mainEnd 102 | if "%OS%"=="Windows_NT" endlocal 103 | 104 | :omega 105 | -------------------------------------------------------------------------------- /plugin/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `java-gradle-plugin` 3 | kotlin("jvm") version "1.3.41" 4 | `maven-publish` 5 | id("com.gradle.plugin-publish") version "0.12.0" 6 | } 7 | 8 | pluginBundle { 9 | website = "https://github.com/thombergs/spring-boot-devtools-gradle-plugin" 10 | vcsUrl = "https://github.com/thombergs/spring-boot-devtools-gradle-plugin.git" 11 | tags = listOf("spring boot", "devtools") 12 | } 13 | 14 | group = "io.reflectoring.spring-boot-devtools" 15 | version = "0.0.3" 16 | 17 | repositories { 18 | jcenter() 19 | } 20 | 21 | gradlePlugin { 22 | plugins { 23 | create("simplePlugin") { 24 | id = "io.reflectoring.spring-boot-devtools" 25 | implementationClass = "io.reflectoring.devtools.DevToolsPlugin" 26 | displayName = "Spring Boot Dev Tools plugin" 27 | description = "Accelerate the dev loop for your single- or multi-module Spring Boot application." 28 | } 29 | } 30 | } 31 | 32 | tasks.register("printVersion") { 33 | println(project.version) 34 | } 35 | 36 | dependencies { 37 | implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.41") 38 | implementation("org.jetbrains.kotlin:kotlin-reflect:1.3.41") 39 | testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.2") 40 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.2") 41 | testImplementation("org.assertj:assertj-core:3.16.1") 42 | } 43 | 44 | tasks { 45 | test { 46 | useJUnitPlatform() 47 | } 48 | } -------------------------------------------------------------------------------- /plugin/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thombergs/spring-boot-devtools-gradle-plugin/b71827164792eefe93864cf2ddb99c752991a689/plugin/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /plugin/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /plugin/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /plugin/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | 88 | @rem Execute Gradle 89 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 90 | 91 | :end 92 | @rem End local scope for the variables with windows NT shell 93 | if "%ERRORLEVEL%"=="0" goto mainEnd 94 | 95 | :fail 96 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 97 | rem the _cmd.exe /c_ return code! 98 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 99 | exit /b 1 100 | 101 | :mainEnd 102 | if "%OS%"=="Windows_NT" endlocal 103 | 104 | :omega 105 | -------------------------------------------------------------------------------- /plugin/src/main/kotlin/io/reflectoring/devtools/DevToolsPlugin.kt: -------------------------------------------------------------------------------- 1 | package io.reflectoring.devtools 2 | 3 | import org.gradle.api.Action 4 | import org.gradle.api.Plugin 5 | import org.gradle.api.Project 6 | import org.gradle.api.Task 7 | import org.gradle.api.artifacts.Configuration 8 | import org.gradle.api.artifacts.ResolvedDependency 9 | import org.gradle.api.artifacts.UnknownConfigurationException 10 | import org.gradle.api.tasks.Copy 11 | import java.io.File 12 | 13 | class DevToolsPlugin : Plugin { 14 | 15 | companion object { 16 | const val EXTENSION_NAME = "devtools" 17 | const val RESTART_CONFIGURATION_NAME = "restart" 18 | const val RESTART_TASK_NAME = "restart" 19 | const val RELOAD_CONFIGURATION_NAME = "reload" 20 | const val RELOAD_TASK_NAME = "reload" 21 | 22 | // Default list of folders that Spring Boot Dev Tools will not trigger a restart for 23 | // when a file in them changes. 24 | val RESOURCES_EXCLUDED_FROM_RESTART = listOf( 25 | "/META-INF/maven/**", 26 | "/META-INF/resources/**", 27 | "/resources/**", 28 | "/static/**", 29 | "/public/**", 30 | "/templates/**" 31 | ) 32 | } 33 | 34 | lateinit var project: Project 35 | 36 | override fun apply(project: Project) { 37 | this.project = project 38 | createExtension() 39 | 40 | val restartConfiguration = addOrCreateConfiguration(project, RESTART_CONFIGURATION_NAME) 41 | val reloadConfiguration = addOrCreateConfiguration(project, RELOAD_CONFIGURATION_NAME) 42 | 43 | project.afterEvaluate { 44 | addDevToolsDependency(project) 45 | val reloadTask = addReloadTask(reloadConfiguration, project) 46 | addRestartTask(restartConfiguration, project, reloadTask) 47 | } 48 | 49 | } 50 | 51 | private fun addRestartTask(restartConfiguration: Configuration, project: Project, reloadTask: Task) { 52 | val subTasks = mutableListOf(reloadTask) 53 | restartConfiguration.resolve() 54 | restartConfiguration.resolvedConfiguration.firstLevelModuleDependencies.forEach { dependency -> 55 | subTasks.add(createRestartModuleTask(dependency)) 56 | } 57 | createRestartTask(project, subTasks) 58 | } 59 | 60 | private fun addReloadTask(reloadConfiguration: Configuration, project: Project) : Task{ 61 | val subTasks = mutableListOf() 62 | reloadConfiguration.resolve() 63 | reloadConfiguration.resolvedConfiguration.firstLevelModuleDependencies.forEach { dependency -> 64 | subTasks.add(createReloadModuleTask(dependency)) 65 | } 66 | return createReloadTask(project, subTasks) 67 | } 68 | 69 | 70 | /** 71 | * Creates the "reload" task for the main module that contains the Spring Boot application. 72 | * The reload task updates all static resources that don't need a restart and creates a trigger file 73 | * to trigger Spring Boot Dev Tools for a reload. 74 | */ 75 | private fun createReloadTask(project: Project, tasks: List) : Task{ 76 | val reloadTask = project.tasks.create(RELOAD_TASK_NAME, Copy::class.java) 77 | 78 | reloadTask.from("src/main/resources") 79 | reloadTask.into("build/resources/main") 80 | 81 | for(folder in RESOURCES_EXCLUDED_FROM_RESTART){ 82 | reloadTask.include(folder) 83 | } 84 | 85 | 86 | for (task in tasks) { 87 | reloadTask.dependsOn(task) 88 | } 89 | reloadTask.actions.add(Action { 90 | touchTriggerFile() 91 | }) 92 | 93 | return reloadTask 94 | } 95 | 96 | /** 97 | * Creates the "restart" task for the main module that contains the Spring Boot application. 98 | * The restart task compiles the main modules sources, calls the restart tasks for all sub modules, 99 | * and creates a trigger file to trigger Spring Boot Dev Tools. 100 | */ 101 | private fun createRestartTask(project: Project, tasks: List) { 102 | val restartTask = project.tasks.create(RESTART_TASK_NAME) 103 | restartTask.dependsOn("classes") 104 | for (task in tasks) { 105 | restartTask.dependsOn(task) 106 | } 107 | restartTask.actions.add(Action { 108 | touchTriggerFile() 109 | }) 110 | } 111 | 112 | private fun createRestartModuleTask(module: ResolvedDependency): Task { 113 | val restartModuleTask = project.tasks.create("restart-${module.moduleName}", Copy::class.java) 114 | module.moduleArtifacts.forEach { 115 | if (it.type == "jar") { 116 | val dependencyRootDir = it.file.parentFile.parentFile.parentFile 117 | 118 | val classesSourceFolder = "${dependencyRootDir}/build/classes" 119 | val classesTargetFolder = "${project.buildDir}/classes" 120 | 121 | restartModuleTask.from(classesSourceFolder) 122 | restartModuleTask.into(classesTargetFolder) 123 | 124 | val dependencyString = toFullDependencyString(dependencyRootDir) 125 | val moduleConfig = getExtension().getModuleConfig(dependencyString) 126 | 127 | // we always want to run the "classes" task when restarting 128 | restartModuleTask.dependsOn("${moduleConfig.dependency}:classes") 129 | 130 | // if there is a custom reload task, we want to run that, too, when restarting 131 | moduleConfig.reloadTask?.let { 132 | restartModuleTask.dependsOn("${moduleConfig.dependency}:${moduleConfig.reloadTask}") 133 | } 134 | return restartModuleTask 135 | } 136 | } 137 | 138 | throw IllegalStateException("Module ${module.moduleName} does not publish a JAR file!") 139 | } 140 | 141 | private fun createReloadModuleTask(module: ResolvedDependency): Task { 142 | val reloadModuleTask = project.tasks.create("reload-${module.moduleName}", Copy::class.java) 143 | module.moduleArtifacts.forEach { 144 | if (it.type == "jar") { 145 | val dependencyRootDir = it.file.parentFile.parentFile.parentFile 146 | 147 | val resourcesSourceFolder = "${dependencyRootDir}/src/main/resources" 148 | val resourcesTargetFolder = "${project.buildDir}/resources/main" 149 | 150 | reloadModuleTask.from(resourcesSourceFolder) 151 | reloadModuleTask.into(resourcesTargetFolder) 152 | 153 | for(folder in RESOURCES_EXCLUDED_FROM_RESTART){ 154 | reloadModuleTask.include(folder) 155 | } 156 | 157 | val dependencyString = toFullDependencyString(dependencyRootDir) 158 | val moduleConfig = getExtension().getModuleConfig(dependencyString) 159 | 160 | // if there is a custom reload task, we want to run that when reloading 161 | moduleConfig.reloadTask?.let { 162 | reloadModuleTask.dependsOn("${moduleConfig.dependency}:${moduleConfig.reloadTask}") 163 | } 164 | return reloadModuleTask 165 | } 166 | } 167 | 168 | throw IllegalStateException("Module ${module.moduleName} does not publish a JAR file!") 169 | } 170 | 171 | private fun createExtension() { 172 | val modules = project.container(ModuleConfig::class.java) 173 | project.extensions.create(EXTENSION_NAME, DevToolsPluginConfig::class.java, modules) 174 | } 175 | 176 | private fun getExtension(): DevToolsPluginConfig { 177 | return project.extensions.findByName(EXTENSION_NAME) as DevToolsPluginConfig 178 | } 179 | 180 | private fun touchTriggerFile() { 181 | val triggerFileName = getExtension().triggerFile 182 | val triggerFile = File(project.buildDir, triggerFileName) 183 | if (!triggerFile.exists()) { 184 | triggerFile.createNewFile() 185 | } else { 186 | triggerFile.setLastModified(System.currentTimeMillis()) 187 | } 188 | } 189 | 190 | private fun toFullDependencyString(dependencyRootDir: File): String { 191 | val rootDir = project.rootProject.rootDir 192 | val relativePath = dependencyRootDir.absolutePath.replaceFirst(rootDir.absolutePath, "") 193 | return relativePath.replace("/", ":") 194 | } 195 | 196 | /** 197 | * Adds the dependency to spring-boot-devtools so the user doesn't have to. 198 | *

199 | * The dependency is added to the "developmentOnly" configuration that is also 200 | * provided by the Spring Boot Gradle plugin, so we re-use that configuration 201 | * if it exists already. 202 | */ 203 | private fun addDevToolsDependency(project: Project) { 204 | val developmentOnlyConfiguration = addOrCreateConfiguration(project, "developmentOnly") 205 | val springBootPlugin = project.plugins.findPlugin("org.springframework.boot") 206 | val devToolsDependency = developmentOnlyConfiguration.dependencies.find { it.name == "spring-boot-devtools" } 207 | 208 | // the project already has the dependency and we're not going to overriding it 209 | if (devToolsDependency != null) { 210 | return 211 | } 212 | 213 | // we're adding the dependency without a version to let the Spring Dependency plugin select the version 214 | if (springBootPlugin != null) { 215 | project.dependencies.add(developmentOnlyConfiguration.name, "org.springframework.boot:spring-boot-devtools") 216 | return 217 | } 218 | 219 | // we're adding the latest version of the dependency 220 | project.dependencies.add(developmentOnlyConfiguration.name, "org.springframework.boot:spring-boot-devtools:2.3.2.RELEASE") 221 | } 222 | 223 | private fun addOrCreateConfiguration(project: Project, configurationName: String): Configuration { 224 | return try { 225 | project.configurations.getByName(configurationName); 226 | } catch (e: UnknownConfigurationException) { 227 | project.configurations.create(configurationName) 228 | } 229 | } 230 | 231 | 232 | } -------------------------------------------------------------------------------- /plugin/src/main/kotlin/io/reflectoring/devtools/DevToolsPluginDsl.kt: -------------------------------------------------------------------------------- 1 | package io.reflectoring.devtools 2 | 3 | import groovy.lang.Closure 4 | import org.gradle.api.NamedDomainObjectContainer 5 | import kotlin.streams.asSequence 6 | 7 | /** 8 | * Entrypoint to the DSL that can be used to configure the DevToolsPlugin. 9 | */ 10 | open class DevToolsPluginConfig( 11 | var modules: NamedDomainObjectContainer 12 | ) { 13 | 14 | /** 15 | * The name of the trigger file. The plugin will create this file in the build folder after all files have 16 | * been copied. Default: ".triggerFile". 17 | *

18 | * Use the same file name to configure the property "devtools.restart.trigger-file" in your application.yml. 19 | */ 20 | var triggerFile: String = ".triggerFile" 21 | 22 | fun modules(closure: Closure) { 23 | modules.configure(closure) 24 | } 25 | 26 | /** 27 | * Returns the ModuleConfig for the given dependency. Returns a default ModuleConfig if no ModuleConfig exists 28 | * for the given dependency. 29 | * @param dependency a Gradle module dependency string (for example ":common:logging" when the module is in the folder "/common/logging"). 30 | */ 31 | internal fun getModuleConfig(dependency: String): ModuleConfig { 32 | val moduleConfig = modules.stream().asSequence() 33 | .filter { it.dependency == dependency } 34 | .firstOrNull() 35 | 36 | return moduleConfig ?: ModuleConfig("default", dependency) 37 | } 38 | } 39 | 40 | /** 41 | * Configures parameters for a module. 42 | */ 43 | open class ModuleConfig( 44 | /** 45 | * The name of the config. This is used as the key in the NamedDomainObjectContainer. 46 | */ 47 | val name: String 48 | ) { 49 | 50 | /** 51 | * The dependency string to the module that is to be configured. This string should be the same as defined 52 | * in the "dependencies" closure in build.gradle (for example ":common:logging"). 53 | */ 54 | var dependency: String = "default" 55 | 56 | /** 57 | * An additional task that should be called for this module before triggering a reload in Spring Boot Dev Tools. 58 | * The task is expected to contribute static resources to the "build/classes" folder of the module. 59 | * By default, a task named "reload" will be created that copies all files from "src/main/resources/static" and 60 | * "src/main/resources/templates". The task defined here will be called in addition to the default task. 61 | */ 62 | var reloadTask: String? = null 63 | 64 | constructor(name: String, dependency: String) : this(name) { 65 | this.dependency = dependency 66 | } 67 | 68 | } -------------------------------------------------------------------------------- /plugin/src/test/kotlin/io/reflectoring/devtools/BuildTaskAssert.kt: -------------------------------------------------------------------------------- 1 | package io.reflectoring.devtools 2 | 3 | import org.assertj.core.api.AbstractAssert 4 | import org.gradle.testkit.runner.BuildTask 5 | import org.gradle.testkit.runner.TaskOutcome 6 | import java.util.* 7 | 8 | class BuildTaskAssert(actual: BuildTask?) : AbstractAssert(actual, BuildTaskAssert::class.java) { 9 | 10 | companion object { 11 | fun assertThat(actual: BuildTask?): BuildTaskAssert { 12 | return BuildTaskAssert(actual) 13 | } 14 | } 15 | 16 | fun hasAnyOutcome(vararg expectedOutcomes: TaskOutcome): BuildTaskAssert { 17 | val actualOutcome = actual?.outcome 18 | for (expectedOutcome in expectedOutcomes) { 19 | if (Objects.equals(actualOutcome, expectedOutcome)) { 20 | return this 21 | } 22 | } 23 | failWithMessage("Task has outcome $actualOutcome, but expected one of these: ${expectedOutcomes.map { it.name }}") 24 | return this 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /plugin/src/test/kotlin/io/reflectoring/devtools/Files.kt: -------------------------------------------------------------------------------- 1 | package io.reflectoring.devtools 2 | 3 | import org.assertj.core.api.Assertions.assertThat 4 | 5 | 6 | class Files(private val debug: Boolean = false) { 7 | 8 | private val sourceFiles: MutableList = mutableListOf() 9 | private val targetFiles: MutableList = mutableListOf() 10 | 11 | fun addSourceFile(filepath: String, content: String) { 12 | val file = SourceFile(filepath, content) 13 | file.create() 14 | this.sourceFiles.add(file) 15 | } 16 | 17 | fun addJavaSourceFile(filepath: String, packageName: String) { 18 | val file = SourceFile(filepath, """ 19 | package $packageName; 20 | 21 | public class Test { 22 | 23 | public static void main(String[] args) { 24 | System.out.println("Hello world!"); 25 | } 26 | } 27 | """) 28 | file.create() 29 | this.sourceFiles.add(file) 30 | } 31 | 32 | fun addPropertiesSourceFile(filepath: String) { 33 | val file = SourceFile(filepath, """ 34 | foo=bar 35 | """) 36 | file.create() 37 | this.sourceFiles.add(file) 38 | } 39 | 40 | fun expectTargetFile(filepath: String) { 41 | this.targetFiles.add(TargetFile(filepath)) 42 | } 43 | 44 | fun assertTargetFilesExist() { 45 | for (file in targetFiles) { 46 | assertThat(file.exists()) 47 | .withFailMessage("Expected file ${file.filepath} to exist!") 48 | .isTrue() 49 | 50 | 51 | } 52 | cleanup() 53 | } 54 | 55 | fun cleanup() { 56 | if (!debug) { 57 | for (file in sourceFiles) { 58 | file.delete() 59 | } 60 | for (file in targetFiles) { 61 | file.delete() 62 | } 63 | } 64 | } 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /plugin/src/test/kotlin/io/reflectoring/devtools/MultiModuleTests.kt: -------------------------------------------------------------------------------- 1 | package io.reflectoring.devtools 2 | 3 | import io.reflectoring.devtools.BuildTaskAssert.Companion.assertThat 4 | import org.gradle.testkit.runner.GradleRunner 5 | import org.gradle.testkit.runner.TaskOutcome 6 | import org.junit.jupiter.api.AfterEach 7 | import org.junit.jupiter.api.Test 8 | import java.io.File 9 | 10 | class MultiModuleTests { 11 | 12 | companion object { 13 | const val WORK_DIR = "../samples/multi-module" 14 | } 15 | 16 | @AfterEach 17 | fun cleanup() { 18 | val buildFile = File("$WORK_DIR/app", "build.gradle") 19 | buildFile.delete() 20 | } 21 | 22 | @Test 23 | fun restartWithDefaultConfiguration() { 24 | val workDir = prepareBuildfile("default-configuration.gradle") 25 | 26 | val files = restartFilesConfiguration() 27 | files.expectTargetFile("$WORK_DIR/app/build/.triggerFile") 28 | 29 | val result = GradleRunner.create() 30 | .withProjectDir(workDir) 31 | .withArguments("clean", "restart") 32 | .withPluginClasspath() 33 | .build() 34 | 35 | assertThat(result.task(":app:restart")).hasAnyOutcome(TaskOutcome.SUCCESS) 36 | files.assertTargetFilesExist() 37 | } 38 | 39 | @Test 40 | fun restartWithCustomConfiguration() { 41 | val workDir = prepareBuildfile("custom-configuration.gradle") 42 | 43 | val files = restartFilesConfiguration() 44 | files.expectTargetFile("$WORK_DIR/app/build/.triggerFile") 45 | 46 | val result = GradleRunner.create() 47 | .withProjectDir(workDir) 48 | .withArguments("clean", "restart") 49 | .withPluginClasspath() 50 | .build() 51 | 52 | assertThat(result.task(":app:restart")).hasAnyOutcome(TaskOutcome.SUCCESS) 53 | assertThat(result.task(":module1:customProcessResources")).hasAnyOutcome(TaskOutcome.SUCCESS, TaskOutcome.UP_TO_DATE) 54 | files.assertTargetFilesExist() 55 | } 56 | 57 | @Test 58 | fun reloadWithDefaultConfiguration() { 59 | val workDir = prepareBuildfile("default-configuration.gradle") 60 | 61 | val files = reloadFilesConfiguration() 62 | files.expectTargetFile("$WORK_DIR/app/build/.triggerFile") 63 | 64 | val result = GradleRunner.create() 65 | .withProjectDir(workDir) 66 | .withArguments("clean", "reload") 67 | .withPluginClasspath() 68 | .build() 69 | 70 | assertThat(result.task(":app:reload")).hasAnyOutcome(TaskOutcome.SUCCESS) 71 | files.assertTargetFilesExist() 72 | } 73 | 74 | @Test 75 | fun reloadWithCustomConfiguration() { 76 | val workDir = prepareBuildfile("custom-configuration.gradle") 77 | 78 | val files = reloadFilesConfiguration() 79 | files.expectTargetFile("$WORK_DIR/app/build/.triggerFile") 80 | 81 | val result = GradleRunner.create() 82 | .withProjectDir(workDir) 83 | .withArguments("clean", "reload") 84 | .withPluginClasspath() 85 | .build() 86 | 87 | assertThat(result.task(":app:reload")).hasAnyOutcome(TaskOutcome.SUCCESS) 88 | assertThat(result.task(":module1:customProcessResources")).hasAnyOutcome(TaskOutcome.SUCCESS, TaskOutcome.UP_TO_DATE) 89 | files.assertTargetFilesExist() 90 | } 91 | 92 | private fun restartFilesConfiguration() : Files{ 93 | val files = reloadFilesConfiguration() 94 | files.addJavaSourceFile("$WORK_DIR/app/src/main/java/io/reflectoring/app/Test.java", "io.reflectoring.app") 95 | files.expectTargetFile("$WORK_DIR/app/build/classes/java/main/io/reflectoring/app/Test.class") 96 | 97 | files.addJavaSourceFile("$WORK_DIR/module1/src/main/java/io/reflectoring/module1/Test.java", "io.reflectoring.module1") 98 | files.expectTargetFile("$WORK_DIR/app/build/classes/java/main/io/reflectoring/module1/Test.class") 99 | 100 | files.addJavaSourceFile("$WORK_DIR/module2/src/main/java/io/reflectoring/module2/Test.java", "io.reflectoring.module2") 101 | files.expectTargetFile("$WORK_DIR/app/build/classes/java/main/io/reflectoring/module2/Test.class") 102 | 103 | return files 104 | } 105 | 106 | private fun reloadFilesConfiguration() : Files { 107 | val files = Files() 108 | files.addPropertiesSourceFile("$WORK_DIR/app/src/main/resources/templates/main.html") 109 | files.expectTargetFile("$WORK_DIR/app/build/resources/main/templates/main.html") 110 | 111 | files.addPropertiesSourceFile("$WORK_DIR/module1/src/main/resources/templates/module1.html") 112 | files.expectTargetFile("$WORK_DIR/app/build/resources/main/templates/module1.html") 113 | 114 | files.addPropertiesSourceFile("$WORK_DIR/module2/src/main/resources/templates/module2.html") 115 | files.expectTargetFile("$WORK_DIR/app/build/resources/main/templates/main.html") 116 | return files 117 | } 118 | 119 | private fun prepareBuildfile(buildFileName: String): File { 120 | val workDir = File("$WORK_DIR/app") 121 | val buildFile = File(workDir, buildFileName) 122 | val targetBuildFile = File(workDir, "build.gradle") 123 | buildFile.copyTo(targetBuildFile, overwrite = true) 124 | return workDir 125 | } 126 | 127 | 128 | } -------------------------------------------------------------------------------- /plugin/src/test/kotlin/io/reflectoring/devtools/SingleModuleTests.kt: -------------------------------------------------------------------------------- 1 | package io.reflectoring.devtools 2 | 3 | import io.reflectoring.devtools.BuildTaskAssert.Companion.assertThat 4 | import org.gradle.testkit.runner.GradleRunner 5 | import org.gradle.testkit.runner.TaskOutcome 6 | import org.junit.jupiter.api.AfterEach 7 | import org.junit.jupiter.api.Test 8 | import java.io.File 9 | 10 | class SingleModuleTests { 11 | 12 | companion object { 13 | const val WORK_DIR = "../samples/single-module" 14 | } 15 | 16 | @AfterEach 17 | fun cleanup() { 18 | val buildFile = File(WORK_DIR, "build.gradle") 19 | buildFile.delete() 20 | } 21 | 22 | @Test 23 | fun defaultConfiguration() { 24 | val workDir = prepareBuildfile("default-configuration.gradle") 25 | 26 | val files = Files() 27 | files.addJavaSourceFile("$WORK_DIR/src/main/java/io/reflectoring/devtools/Test.java", "io.reflectoring.devtools") 28 | files.expectTargetFile("$WORK_DIR/build/classes/java/main/io/reflectoring/devtools/Test.class") 29 | files.addPropertiesSourceFile("$WORK_DIR/src/main/resources/test.properties") 30 | files.expectTargetFile("$WORK_DIR/build/resources/main/test.properties") 31 | files.expectTargetFile("$WORK_DIR/build/.triggerFile") 32 | 33 | val resultAfterChange = GradleRunner.create() 34 | .withProjectDir(workDir) 35 | .withArguments("clean", "restart") 36 | .withPluginClasspath() 37 | .build() 38 | 39 | assertThat(resultAfterChange.task(":restart")).hasAnyOutcome(TaskOutcome.SUCCESS) 40 | assertThat(resultAfterChange.task(":compileJava")).hasAnyOutcome(TaskOutcome.SUCCESS) 41 | assertThat(resultAfterChange.task(":processResources")).hasAnyOutcome(TaskOutcome.SUCCESS) 42 | files.assertTargetFilesExist() 43 | } 44 | 45 | @Test 46 | fun customTriggerFile() { 47 | val workDir = prepareBuildfile("custom-trigger-file.gradle") 48 | 49 | val files = Files() 50 | files.expectTargetFile("$WORK_DIR/build/.customTriggerFile") 51 | 52 | val result = GradleRunner.create() 53 | .withProjectDir(workDir) 54 | .withArguments("clean", "restart") 55 | .withPluginClasspath() 56 | .build() 57 | 58 | assertThat(result.task(":restart")).hasAnyOutcome(TaskOutcome.SUCCESS) 59 | assertThat(result.task(":compileJava")).hasAnyOutcome(TaskOutcome.SUCCESS) 60 | assertThat(result.task(":processResources")).hasAnyOutcome(TaskOutcome.SUCCESS) 61 | files.assertTargetFilesExist() 62 | } 63 | 64 | private fun prepareBuildfile(buildFileName: String): File { 65 | val workDir = File(WORK_DIR) 66 | val buildFile = File(workDir, buildFileName) 67 | val targetBuildFile = File(workDir, "build.gradle") 68 | buildFile.copyTo(targetBuildFile, overwrite = true) 69 | return workDir 70 | } 71 | 72 | 73 | } -------------------------------------------------------------------------------- /plugin/src/test/kotlin/io/reflectoring/devtools/SourceFile.kt: -------------------------------------------------------------------------------- 1 | package io.reflectoring.devtools 2 | 3 | import java.io.File 4 | import java.io.FileWriter 5 | 6 | /** 7 | * A file that is expected to be picked up in a source location by the plugin. 8 | */ 9 | data class SourceFile( 10 | val filepath: String, 11 | val content: String 12 | ) { 13 | fun create() { 14 | val file = File(filepath) 15 | file.parentFile.mkdirs() 16 | file.createNewFile() 17 | val writer = FileWriter(file) 18 | writer.write(content) 19 | writer.flush() 20 | writer.close() 21 | } 22 | 23 | fun delete(){ 24 | File(this.filepath).delete() 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /plugin/src/test/kotlin/io/reflectoring/devtools/TargetFile.kt: -------------------------------------------------------------------------------- 1 | package io.reflectoring.devtools 2 | 3 | import java.io.File 4 | 5 | /** 6 | * A file that is expected to be created in a target location by the plugin. 7 | */ 8 | data class TargetFile( 9 | val filepath: String 10 | ) { 11 | fun exists(): Boolean { 12 | return File(this.filepath).exists() 13 | } 14 | 15 | fun delete(){ 16 | File(this.filepath).delete() 17 | } 18 | } -------------------------------------------------------------------------------- /samples/multi-module/README.md: -------------------------------------------------------------------------------- 1 | # Multi-module sample 2 | 3 | This sample shows how to configure the Spring Boot Dev Tools plugin for a multi-module Gradle build. 4 | 5 | Rename one of the following files to `build.gradle`: 6 | * `/app/default-configuration.gradle` 7 | * `/app/custom-configuration.gradle` 8 | 9 | Then, start the Spring Boot app with `./gradlew bootrun`. 10 | 11 | Change any of the files in the following locations while the app is running (or add new files): 12 | * `/app/src/main/java` 13 | * `/app/src/main/resources` 14 | * `/module1/src/main/java` 15 | * `/module1/src/main/resources` 16 | * `/module2/src/main/java` 17 | * `/module2/src/main/resources` 18 | 19 | Then, run `./gradlew restart` and refresh the page. Your changes should be visible. -------------------------------------------------------------------------------- /samples/multi-module/app/custom-configuration.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.3.2.RELEASE' 3 | id 'io.reflectoring.spring-boot-devtools' 4 | } 5 | 6 | dependencies { 7 | implementation project(':module1') 8 | implementation project(':module2') 9 | 10 | restart project(':module1') 11 | restart project(':module2') 12 | 13 | reload project(':module1') 14 | reload project(':module2') 15 | 16 | implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' 17 | implementation 'org.springframework.boot:spring-boot-starter-web' 18 | testImplementation('org.springframework.boot:spring-boot-starter-test') { 19 | exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' 20 | } 21 | } 22 | 23 | test { 24 | useJUnitPlatform() 25 | } 26 | 27 | devtools { 28 | modules { 29 | module1 { 30 | dependency = ":module1" 31 | reloadTask = "customProcessResources" 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /samples/multi-module/app/default-configuration.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.3.2.RELEASE' 3 | id 'io.reflectoring.spring-boot-devtools' 4 | } 5 | 6 | dependencies { 7 | implementation project(':module1') 8 | implementation project(':module2') 9 | 10 | restart project(':module1') 11 | restart project(':module2') 12 | 13 | reload project(':module1') 14 | reload project(':module2') 15 | 16 | implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' 17 | implementation 'org.springframework.boot:spring-boot-starter-web' 18 | testImplementation('org.springframework.boot:spring-boot-starter-test') { 19 | exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' 20 | } 21 | } 22 | 23 | test { 24 | useJUnitPlatform() 25 | } -------------------------------------------------------------------------------- /samples/multi-module/app/src/main/java/io/reflectoring/app/DevtoolsDemoApplication.java: -------------------------------------------------------------------------------- 1 | package io.reflectoring.app; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class DevtoolsDemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(DevtoolsDemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /samples/multi-module/app/src/main/java/io/reflectoring/app/HelloController.java: -------------------------------------------------------------------------------- 1 | package io.reflectoring.app; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.servlet.ModelAndView; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | @Controller 11 | class HelloController { 12 | 13 | @GetMapping("/") 14 | ModelAndView hello(){ 15 | Map model = new HashMap<>(); 16 | model.put("module", "Main module"); 17 | return new ModelAndView("main.html", model); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /samples/multi-module/app/src/main/resources/META-INF/spring-devtools.properties: -------------------------------------------------------------------------------- 1 | restart.include.modules=/devtools-demo.*\.jar -------------------------------------------------------------------------------- /samples/multi-module/app/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | devtools: 2 | restart: 3 | trigger-file: .triggerFile 4 | additional-paths: build -------------------------------------------------------------------------------- /samples/multi-module/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'io.spring.dependency-management' version '1.0.9.RELEASE' 3 | } 4 | 5 | 6 | subprojects { 7 | 8 | apply plugin: 'java' 9 | apply plugin: 'io.spring.dependency-management' 10 | apply plugin: 'java-library' 11 | 12 | jar.baseName("devtools-demo-${project.name}") 13 | 14 | group = 'io.reflectoring' 15 | version = '0.0.1-SNAPSHOT' 16 | sourceCompatibility = '13' 17 | 18 | dependencyManagement { 19 | imports { 20 | mavenBom("org.springframework.boot:spring-boot-dependencies:2.3.2.RELEASE") 21 | } 22 | } 23 | 24 | repositories { 25 | mavenCentral() 26 | } 27 | 28 | dependencies { 29 | } 30 | 31 | test { 32 | useJUnitPlatform() 33 | } 34 | 35 | } 36 | 37 | -------------------------------------------------------------------------------- /samples/multi-module/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thombergs/spring-boot-devtools-gradle-plugin/b71827164792eefe93864cf2ddb99c752991a689/samples/multi-module/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/multi-module/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /samples/multi-module/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /samples/multi-module/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | 88 | @rem Execute Gradle 89 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 90 | 91 | :end 92 | @rem End local scope for the variables with windows NT shell 93 | if "%ERRORLEVEL%"=="0" goto mainEnd 94 | 95 | :fail 96 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 97 | rem the _cmd.exe /c_ return code! 98 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 99 | exit /b 1 100 | 101 | :mainEnd 102 | if "%OS%"=="Windows_NT" endlocal 103 | 104 | :omega 105 | -------------------------------------------------------------------------------- /samples/multi-module/module1/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation 'org.springframework.boot:spring-boot-starter-web' 3 | } 4 | 5 | task customProcessResources { 6 | dependsOn('processResources') 7 | } 8 | 9 | task customCompileJava { 10 | dependsOn('compileJava') 11 | } 12 | -------------------------------------------------------------------------------- /samples/multi-module/module1/src/main/java/io/reflectoring/module1/Module1Configuration.java: -------------------------------------------------------------------------------- 1 | package io.reflectoring.module1; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | @Configuration 7 | @ComponentScan 8 | class Module1Configuration { 9 | } 10 | -------------------------------------------------------------------------------- /samples/multi-module/module1/src/main/java/io/reflectoring/module1/Module1Controller.java: -------------------------------------------------------------------------------- 1 | package io.reflectoring.module1; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.servlet.ModelAndView; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | @Controller 11 | class Module1Controller { 12 | 13 | @GetMapping("/module1") 14 | ModelAndView hello(){ 15 | Map model = new HashMap<>(); 16 | model.put("module", "Module 1"); 17 | return new ModelAndView("module1.html", model); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /samples/multi-module/module1/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | io.reflectoring.module1.Module1Configuration -------------------------------------------------------------------------------- /samples/multi-module/module1/src/main/resources/static/github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thombergs/spring-boot-devtools-gradle-plugin/b71827164792eefe93864cf2ddb99c752991a689/samples/multi-module/module1/src/main/resources/static/github.png -------------------------------------------------------------------------------- /samples/multi-module/module2/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation 'org.springframework.boot:spring-boot-starter-web' 3 | } 4 | -------------------------------------------------------------------------------- /samples/multi-module/module2/src/main/java/io/reflectoring/module2/Module2Configuration.java: -------------------------------------------------------------------------------- 1 | package io.reflectoring.module2; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | @Configuration 7 | @ComponentScan 8 | class Module2Configuration { 9 | } 10 | -------------------------------------------------------------------------------- /samples/multi-module/module2/src/main/java/io/reflectoring/module2/Module2Controller.java: -------------------------------------------------------------------------------- 1 | package io.reflectoring.module2; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.servlet.ModelAndView; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | @Controller 11 | class Module2Controller { 12 | 13 | @GetMapping("/module2") 14 | ModelAndView hello() { 15 | Map model = new HashMap<>(); 16 | model.put("module", "Module 2"); 17 | return new ModelAndView("module2.html", model); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /samples/multi-module/module2/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | io.reflectoring.module2.Module2Configuration -------------------------------------------------------------------------------- /samples/multi-module/settings.gradle: -------------------------------------------------------------------------------- 1 | includeBuild '../../plugin' 2 | 3 | include 'app' 4 | include 'module1' 5 | include 'module2' 6 | -------------------------------------------------------------------------------- /samples/single-module/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | 17 | ### IntelliJ IDEA ### 18 | .idea 19 | *.iws 20 | *.iml 21 | *.ipr 22 | out/ 23 | !**/src/main/**/out/ 24 | !**/src/test/**/out/ 25 | 26 | ### NetBeans ### 27 | /nbproject/private/ 28 | /nbbuild/ 29 | /dist/ 30 | /nbdist/ 31 | /.nb-gradle/ 32 | 33 | ### VS Code ### 34 | .vscode/ 35 | -------------------------------------------------------------------------------- /samples/single-module/README.md: -------------------------------------------------------------------------------- 1 | # Single-module sample 2 | 3 | This sample shows how to configure the Spring Boot Dev Tools plugin for a single-module Gradle build. 4 | 5 | Rename one of the following files to `build.gradle`: 6 | * `default-configuration.gradle` 7 | * `custom-configuration.gradle` 8 | 9 | Then, start the Spring Boot app with `./gradlew bootrun`. 10 | 11 | Change any of the files in the following locations while the app is running (or add new files): 12 | * `/app/src/main/java` 13 | * `/app/src/main/resources` 14 | 15 | Then, run `./gradlew restart` and refresh the page. Your changes should be visible. -------------------------------------------------------------------------------- /samples/single-module/custom-trigger-file.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.3.2.RELEASE' 3 | id 'io.spring.dependency-management' version '1.0.9.RELEASE' 4 | id 'java' 5 | id 'io.reflectoring.spring-boot-devtools' 6 | } 7 | 8 | group = 'io.reflectoring.spring-boot-devtools.samples' 9 | version = '0.0.1-SNAPSHOT' 10 | sourceCompatibility = '11' 11 | 12 | repositories { 13 | mavenCentral() 14 | } 15 | 16 | dependencies { 17 | implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' 18 | implementation 'org.springframework.boot:spring-boot-starter-web' 19 | testImplementation('org.springframework.boot:spring-boot-starter-test') { 20 | exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' 21 | } 22 | } 23 | 24 | test { 25 | useJUnitPlatform() 26 | } 27 | 28 | devtools { 29 | triggerFile = ".customTriggerFile" 30 | } 31 | -------------------------------------------------------------------------------- /samples/single-module/default-configuration.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.3.2.RELEASE' 3 | id 'io.spring.dependency-management' version '1.0.9.RELEASE' 4 | id 'java' 5 | id 'io.reflectoring.spring-boot-devtools' 6 | } 7 | 8 | group = 'io.reflectoring.spring-boot-devtools.samples' 9 | version = '0.0.1-SNAPSHOT' 10 | sourceCompatibility = '11' 11 | 12 | repositories { 13 | mavenCentral() 14 | } 15 | 16 | dependencies { 17 | implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' 18 | implementation 'org.springframework.boot:spring-boot-starter-web' 19 | testImplementation('org.springframework.boot:spring-boot-starter-test') { 20 | exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' 21 | } 22 | } 23 | 24 | test { 25 | useJUnitPlatform() 26 | } 27 | -------------------------------------------------------------------------------- /samples/single-module/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thombergs/spring-boot-devtools-gradle-plugin/b71827164792eefe93864cf2ddb99c752991a689/samples/single-module/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/single-module/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /samples/single-module/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /samples/single-module/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | 88 | @rem Execute Gradle 89 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 90 | 91 | :end 92 | @rem End local scope for the variables with windows NT shell 93 | if "%ERRORLEVEL%"=="0" goto mainEnd 94 | 95 | :fail 96 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 97 | rem the _cmd.exe /c_ return code! 98 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 99 | exit /b 1 100 | 101 | :mainEnd 102 | if "%OS%"=="Windows_NT" endlocal 103 | 104 | :omega 105 | -------------------------------------------------------------------------------- /samples/single-module/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'single-module' 2 | includeBuild '../../plugin' 3 | -------------------------------------------------------------------------------- /samples/single-module/src/main/java/io/reflectoring/springbootdevtools/samples/singlemodule/HelloController.java: -------------------------------------------------------------------------------- 1 | package io.reflectoring.springbootdevtools.samples.singlemodule; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.servlet.ModelAndView; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | @Controller 11 | class HelloController { 12 | 13 | @GetMapping("/") 14 | ModelAndView hello() { 15 | Map model = new HashMap<>(); 16 | model.put("name", "Dave"); 17 | return new ModelAndView("hello.html", model); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /samples/single-module/src/main/java/io/reflectoring/springbootdevtools/samples/singlemodule/SingleModuleApplication.java: -------------------------------------------------------------------------------- 1 | package io.reflectoring.springbootdevtools.samples.singlemodule; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SingleModuleApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SingleModuleApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /samples/single-module/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | devtools: 2 | restart: 3 | trigger-file: .triggerFile 4 | additional-paths: build -------------------------------------------------------------------------------- /samples/single-module/src/main/resources/static/hello.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #CCCCCC 3 | } -------------------------------------------------------------------------------- /samples/single-module/src/main/resources/templates/hello.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

Hello, !

8 | 9 | 10 | Change any of these files: 11 | 12 |
    13 |
  • hello.html
  • 14 |
  • hello.css
  • 15 |
  • HelloController.java
  • 16 |
17 | 18 | Then, run the command ./gradlew reload and reload this page. The changes should be visible within a couple seconds. 19 | 20 | 21 | -------------------------------------------------------------------------------- /samples/single-module/src/test/java/io/reflectoring/springbootdevtools/samples/singlemodule/SingleModuleApplicationTests.java: -------------------------------------------------------------------------------- 1 | package io.reflectoring.springbootdevtools.samples.singlemodule; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SingleModuleApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | --------------------------------------------------------------------------------