I'm learning the maven build process, and there's on point of contention that stands out as not making a whole lot of sense.
The way I understand maven, there's the default lifecycles (default, site, clean), each of which has multiple phases. There are some built-in plugins associated with a few phases, and by adding additional plugins, you are able to add extra functionality to the pre-existing phases.
When you specify a phase to run directly within maven, it will go through all the phases up to this point within the same lifecycle, and end with executing your specified phase. To the best of my knowledge however, spring-boot:run is a goal, and thus should not invoke other phases when run. That being said, running spring-boot:run via maven does run other phases (default-cli, pre-unit-test, default-resources, reserve-container-port, and some others). It looks to me that spring has created some new phases (reserve-container-port for instance), but I'm not sure how to find the jar file in which the configuration for these is located.
My questions thus are twofold:
spring-boot:run a goal as I understand it to be? If so, how does running this goal in turn run other phases? To the best of my knowledge, only specifying a phase as a target will run the other previous phases in order, not directly specifying a goal.Is spring-boot:run a goal as I understand it to be
In fact, spring-boot is a maven plugin and run is one of its goals.
Here is the official documentation of this plugin.
In that documentation, I didn't find the default maven phase in which this goal is executed. But from the GitHub source code, I founnd out that this goal is executed in the TEST_COMPILE phase.
only specifying a phase as a target will run the other previous phases in order, not directly specifying a goal.
In fact, this is how maven works. Here is an introduction to the maven lifecycle.
Where is the configuration file for all of this located?
It is defined in your spring-boot pom parent:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>${spring-boot-starter-parent.version}</version>
</parent>
As the other answer misses a bit of the information I was looking for, I thought I'd add the results of my research in case anyone else is curious. Looking in
C:\HOME_DIR.m2\repository\org\springframework\boot\spring-boot-maven-plugin\VERSION_NUMBER\META-INF\maven\plugin.xml
gives the configuration file for most of the related goals for spring with maven. Specifically, the snippet below describes how the spring-boot:run goal works.
<mojo>
<goal>run</goal>
<description>Run an executable archive application.</description>
<requiresDependencyResolution>test</requiresDependencyResolution>
<requiresDirectInvocation>false</requiresDirectInvocation>
<requiresProject>true</requiresProject>
<requiresReports>false</requiresReports>
<aggregator>false</aggregator>
<requiresOnline>false</requiresOnline>
<inheritedByDefault>true</inheritedByDefault>
<phase>validate</phase>
<executePhase>test-compile</executePhase>
<implementation>org.springframework.boot.maven.RunMojo</implementation>
<language>java</language>
<instantiationStrategy>per-lookup</instantiationStrategy>
<executionStrategy>once-per-session</executionStrategy>
<since>1.0.0</since>
<threadSafe>false</threadSafe>
...
</mojo>
Specifically, the <executePhase> tag (detailed partially at https://maven.apache.org/developers/mojo-api-specification.html), which (I believe) lets this goal execute a different phase as it's run.
I missed this detail before (it doesn't seem to be documented anywhere very well either). Either way, this explanation is satisfactory enough for me. If anyone finds better documentation for this tag, I'd appreciate a link :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With