Explaining maven’s building process

When you are used to build your projects with ant a switch to maven can be quite confusing. Maven works in a different way.

ant
Ant is quite easy to understand and gets you started right a way. You can script from target to target and when you want to preform more complex tasks you can configure your own macro’s with the libraries you want to use.

maven
maven works differently. It uses build faces that are processed depending on the artifact type. With plugins you can connect functionality to different phases, this depends on the plugin that has been defined. Some plugins like maven-surefire-plugin are connected by default to a phase (in this example test) other plugins can be configured on multiple phases. For every phase you specify the goal that has to be executed and that’s the method that will be preformed in that phase. In this example is the goal test of the surefire plugin

lifecycle
example:
for a jar artifact the following phases are executed:

  1. process-resources
  2. compile
  3. process-test-resources
  4. test-compile
  5. test
  6. package
  7. install
  8. deploy

the default life cycle is as followed:

  1. validate
  2. initialize
  3. generate-sources
  4. process-sources
  5. generate-resources
  6. process-resources
  7. compile
  8. process-classes
  9. generate-test-sources
  10. process-test-sources
  11. generate-test-resources
  12. process-test-resources
  13. test-compile
  14. process-test-classes
  15. test
  16. prepare-package
  17. package
  18. pre-integration-test
  19. integration-test
  20. post-integration-test
  21. verify
  22. install
  23. deploy

using the test phase
When you have made some junit test to verify the working of your code you would like that they are executed during the test phase in the building lifecycle. To do this you have to include the maven-surefire-plugin

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-surefire-plugin</artifactId>
	<configuration>
		<includes>
		<include>**/unit/*.java</include>
		</includes>
	</configuration>
</plugin>

Default the maven-surefire-plugin connects to the test phase and when i call the maven fase package

mvn package

maven compiles the code and before it creates the package i see that the unit tests in my unit directory are executed.

For more information about the maven lifecycle check apache.org. And read carefully the documentation of the plugin to see when it executes and to what phases you can bind the plugin.

Welcome to the world of maven.

Popularity: 1% [?]

Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

No Responses to “Explaining maven’s building process”

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Website:
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>