Description
Working on an issue in gradle-pitest-plugin I spotted that spring-boot-gradle-plugin doesn't work well with multiple JavaExec tasks available in the build.
There are a few issues:
- RunApp task takes all JavaExec and try to execute them. There could be some other JavaExec tasks like pitest tasks which executes PIT as a separate JVM process instead of the desired run task. It is not desired to run them as well.
- SpringBootPlugin checks on apply if there is any JavaExec task and only if not adds ApplicationPlugin. Having applied also pitest plugin earlier (or any other plugin with JavaExec task which doesn't run the Main application) results in the fact the ApplicationPlugin is not applied (and not available).
- enhanceRunTasks from SpringBootPlugin enhances only tasks that are added after the spring-boot plugin. This can generate problems if ApplicationPlugin was applied earlier.
- enhanceRunTasks enhances all JavaExec and RunApp tasks. This can break those tasks (like pitest task).
There is a small application created by @lando which reproduces mentioned problems.
I don't know what was the reason (the use cases) to support multiple JavaExec tasks and I'm not sure what would be best to resolve this situation. I have experience only with one Spring Boot project, but maybe in most cases there is an assumption that spring-boot plugin will create and configure ApplicationPlugin plugin (which would work by default). In case of other JavaExec tasks there could be checked the task name. One existing JavaExec task with the name "run" (from ApplicationPlugin) should be accepted. In other cases there should be reported an error listing existing JavaExec tasks (with their names) and the information that task(s) to be enhanced (and run on bootRun) should be explicit configured (by name?) in spring-boot configuration closure. This would (probably) fix issues 1,2,4. Issue 3 could be probably fixed by the move the tasks enhancements to project.afterEvaluate phase when all tasks are known and selected can be enhanced (needs to be verified in practice).
What do you think about that?