… or about how would you proceed to create a maven plugin.
What if you would be in a position to talk 5 minute about all you know about maven? What would you say?
I would say that maven is a tool to manage your software builds, and in maven all work goes through plugin and goals. Afterwards I would continue to define the plugin (is a collection of goals) and goal (performs the action in maven builds) terms. Plugins and goals can be called independently, or as part of a lifecycle phase (is a sequence of name phase). Forward I will point that executing a phase, executes all previously phases.
Maven manages all dependencies you need within a pom.xml file. This file is also used to version your software.
Maven has 3 (three) default lifecycles:
- clean;
- default (has 23 phases);
- site.
Default lifecycle – phases
Maven has various phases comprises in the default lifecycle. The most important of them are:
- compile – this phase will compile the source code of the project.
- test-compile – will compile the test source code presented into the test destination directory.
- test – run the tests.
- package – takes the compiled code and packages it into a distributed format such a jar or a war.
- install – install the package into the local repository for use as a dependency in other projects locally.
- deploy
Plugin and goals
If it would to do a terminology analogy with java programming language, I would say that goals are similar with methods, and plugins are similar with classes.
Mavem commands
To run maven commands, you need maven to your classpath,
1 |
export PATH=/opt/apache-maven-3.6.0/bin:$PATH |
Other maven commands:
1 |
mvn help:effective-pom // command to show the super pom of your pom.xml |
1 |
mvn help:describe -Dplugin=compiler // command to describe the compiler plugin |
1 |
mvn compiler:help -Ddetail=true -Dgoal=compile // command to execute the help goal on the compiler plugin |
Create a maven custom plugin
To create a custom maven plugin, you use the archetype plugin and call the create goal.
Advantages of using maven
- simple project setup with guidelines for best practices
- consistent usage across all projects
- dependency management within a centra repository of JARs
- extensible plugins which can be written in Java or scripting languages