||Get dependency tree|
||Generate a maven project|
||Generate a maven project with
||Run a goal with a phase|
- What are transitive dependencies? Transitive dependencies are dependencies of a project dependency.
- What are the use maven plugins? To define custom maven goals.
- Dependencies can be bound to a different scope. Scopes could be compile or test. For instance, Junit dependency only needed for running test not while the application running.
- Maven has three main groups of actions which are:
- Goal is task. For instance, compile, or packaging a jar file.
- The stage that a goal is executed is a phase. For instance,
- Maven lifecycle is a collection of phases:
- Lifecycles contain phases. Phases map to goals.
- Sample paths that maven look into:
src > test > javafor unit tests. Or
src > main > javafor source codes. Or
src > main > resourcesfor resource files. Or
src > main > webappfor java web applications. The same can be applied to groovy without any further configurations. All these locations are scanned automatically without any configuration to maven. Though, the locations can be changed by manipulating the configurations.
- Run the main class when jar file built without any plugins (Specifying the main entry class in the app):
java -cp [jar file.jar] com.madadipouya.eris.HelloWorld.
mvn installphase? Package phase is done before install phase and only jar file is created in target folder. However, install phase copy the jar file after package phase in local repository directory which is typically located in
.m2folder of the user’s home.
- Print dependency tree:
- Test report can be found at
- Generate a basic maven project:
mvn archetype:generate. The parameters such as
groupIdcan be passed using
mvn archetype:generate -DgroupId=com.madadipouya.eris -DartifactId=eris-weather-service.
- What does
archetype:generatemeans? It means
archetypeplugin and the goal
- Sample groupId:
- Sample artifactId:
- List content of a jar file:
java -tf [jar file name].
- Maven has three default built-in lifecycles which are:
defaultlifecycle is responsible to handle the project deployment.
cleanis for cleaning the project. And
siteis for generating documentations.
- Each maven lifecycle consists of multiple phases. For instance,
defaultlifecycles have the following phases:
validate: validate the project is correct and all necessary information is available.
compile: compile the source code of the project.
test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
package: take the compiled code and package it in its distributable format, such as a JAR.
verify: run any checks on results of integration tests to ensure quality criteria are met.
install: install the package into the local repository, for use as a dependency in other projects locally.
deploy: done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.
- For complete list of phases of different maven lifecycles look at here.
- A maven goal is a plugin which can add functionality to a maven phase. A goal might bound to zero to many phases. If a goal is not bound to any phase that means the goal should be execute separately.
- The phases named with hyphenated-words (
pre-*, post-*, or process-*) are not usually directly called from the command line. These phases sequence the build, producing intermediate results that are not useful outside the build. In the case of invoking
integration-test, the environment may be left in a hanging state.
- A goal can run with phase like:
mvn clean dependency:copy-dependencies package.