Last active
October 12, 2017 10:57
-
-
Save IngmarBoddington/bdf2d3de8309d3e52685 to your computer and use it in GitHub Desktop.
General Maven Use
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mvn [<plugin>:]<goal> | |
- General use | |
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false | |
- Example project create | |
mvn test | |
- Run unit tests specified by pom.xml (need unit dependancies in pom) | |
mvn sonar:sonar | |
- Create sonar report based on pom in current directory | |
Maven 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. | |
- integration-test: process and deploy the package if necessary into an environment where integration tests can be run | |
- verify: run any checks to verify the package is valid and meets quality criteria | |
- install: install the package into the local repository, for use as a dependency in other projects locally | |
- deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects. | |
Artifacts fully qualified name: <groupId>:<artifactId>:<version> | |
POM | |
====== | |
Minimal: | |
<project> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.mycompany.app</groupId> | |
<artifactId>my-app</artifactId> | |
<version>1</version> | |
</project> | |
Maven inherits it's defaults from a super POM if not defined: | |
dependencies | |
developers and contributors | |
plugin lists (including reports) | |
plugin executions with matching ids | |
plugin configuration | |
resources | |
Can be used to specify parent to inherit from: | |
<parent> | |
<groupId>com.mycompany.app</groupId> | |
<artifactId>my-app</artifactId> | |
<version>1</version> | |
</parent> | |
Else can specify modules un the app pom to have a cascade of build: | |
<packaging>pom</packaging> | |
<modules> | |
<module>my-module</module> | |
</modules> | |
Variables are available in the form ${project.<name>} for example ${project.version} | |
In the project file this get be references just using ${version} | |
Additional special variables: | |
project.basedir | |
project.baseUri | |
maven.build.timestamp | |
Setup JavaDocs | |
===== | |
Add to pom.xml: | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-javadoc-plugin</artifactId> | |
<version>2.10.3</version> | |
</plugin> | |
</plugins> | |
</build> | |
Then run mvn javadoc:javadoc | |
References | |
===== | |
http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html | |
http://docs.codehaus.org/display/SONAR/Analyzing+with+Maven | |
http://maven.apache.org/guides/getting-started/index.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment