spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.73k stars 40.58k forks source link

Gradle plugin fails with multiple JavaExec tasks in the build #721

Closed szpak closed 10 years ago

szpak commented 10 years ago

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:

  1. 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.
  2. 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).
  3. enhanceRunTasks from SpringBootPlugin enhances only tasks that are added after the spring-boot plugin. This can generate problems if ApplicationPlugin was applied earlier.
  4. 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?

dsyer commented 10 years ago

All that sounds very sensible, as long as it basically preserves the existing behaviour for "simple" projects with no explicit run exec tasks. Would you like to submit a pull request (see link in README for contributor's agreement)?

szpak commented 10 years ago

I will try to make required modifications, but probably not until May. When do you plan to release 1.0.3?

philwebb commented 10 years ago

I think 794808b6b8d36222db8e63ecf37144ffc3faae95 should have fixed this, please give the latest 1.1.0 SNAPSHOT a go.

szpak commented 10 years ago

Thanks Phil. The problem is not reproducible with the sample application and 1.1.0.M2. @holgerstolzenberg, could you check it with your production system?

holgerstolzenberg commented 10 years ago

I just upgraded to 1.1.0.RC1. It seems the issue is fixed. I can run pitest and bootRun tasks successfully. With the bootRun there was another issue with the ASM but it seems related to spring-loaded. Removed spring-loaded from buildscript dependencies and everything works fine. So I think this can be closed.

@szpak You may want to release 0.33.0-SNAPSHOT now :-)