Saturday, September 12, 2015

Maven in short

1. Dependency management - can download the transitive dependencies (dependencies of a dependency and this can be infinitely transitive)
2. The main phases in maven lifecycle are:
a. Clean - will clean the target directory
b. Compile
c. Test-compile
d. Test
e. Package 
f. Install
g. Deploy
3. A plugin is bound to a lifecycle phase - for example, compiler plugin is bound to compile phase.
4. We can either execute the mvn <phase-name> or mvn <plugin-name>:<goal-name> for example, mvn compile and mvn compiler:compile do the same thing but when we execute mvn compile any other plugin we have bound to compile phase willl be executed too (together with compiler plugin's compile goal).
5. Maven POM is hierarchical - a project's POM is always inheriting from the base maven's super POM (that comes as part of maven). To see this, execute: mvn help:effective-pom and this will show the plugins that are already part of the super POM we are inheriting from.
6. Within the project too, we can build a hierarchy of POM files. We use the <modules> element to define the sub-modules (which have their own POM files) in the parent module/directory.
In parent pom.xml:
<module>server</module> -- this will build server/pom.xml
7. All plugins are listed at -
8. Maven central repo is -
9. Some important plugins:
a. Clean
b. Jar - mvn package (this is phase and jar plugin in bound to package phase) or run explicitly as mvn jar:jar.
i. -Djava.finalName
ii. -Djar.forceCreation=true - jar created every time.
c. Javadoc 
d. Install - packages and puts the archive in local maven repo so other modules/projects can refer to it.
e. Deploy - deploys to remote maven repo (the remote repo configuration is provided in pom.xml in <distributionManagement> element). This repo could be in cloud (running artifactory server for eg.)
f. Surefire - only one goal (test).
g. War - to package web application 
10. Archetype - to create a project based on an archetype (or template for a project). We can create our own complex setup archetype and make it available as a template for new projects in an organization.
a. Mvn archetype:create-from-project - used to create a new archetype based on existing project. All source files which were there in the original project will be present in the new projects created from that archetype.
b. Mvn archetype:generate - to create a new project 
11. Some commands:
a. mvn archetype:generate  (format is <plugin>:<goal>) - used to generate skeleton for new project.
b. mvn idea:idea or eclipse:eclipse -- to generate project in IDE specific way (run it after archetype:generate)
c. Mvn help:describe -Dcmd=compiler:compile -Ddetail - to see what properties are available for compiler plugin (properties like maven.compiler.verbose)
d. Mvn compiler:compile -Dmaven.compiler.verbose=true -- to debug what is going during compilation
e. Mvn -help
f. Mvn -v
g. Mvn <plugin-name>:help (eg. Mvn compiler:help)
h. Mvn -q compile (quite mode - tidys the o/p)
i. Mvn -X -- gives verbose/debug o/p

No comments:

Using a Console Cable (USB TTL Serial Cable) with Raspberry Pi 3

A console cable provides terminal access to Raspberry Pi from say a laptop host without requiring to connect a monitor to Pi's HDMI port...