maven
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
maven [2015/11/07 12:25] – [Version Vodoo] skip | maven [2020/12/27 20:35] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== Maven ===== | ||
+ | Maven is an project automation tool. All the routine work can be automated by one maven script: e.g. compiling, project1 and project2, generating websites, run the tests. | ||
+ | - Maven can manage Maven-artifacts, | ||
+ | - Maven artifacts can depend on other Maven artifacts. | ||
+ | - Maven downloads required artifacts, which the local artifacts depend from - all into one local repository: < | ||
+ | - Maven has an own Project type in Eclipse. Each Maven Project is a Maven artifact. | ||
+ | |||
+ | |||
+ | |||
+ | ^What ^Where^ | ||
+ | | 1. General "what is maven" description. | [[ http:// | ||
+ | | 2. Project requred fileds: groupId, artifactId, version | [[http:// | ||
+ | | 3. Maven Phases, and so the commands | ||
+ | | 4. Further details about Maven | [[ http:// | ||
+ | |||
+ | ==== Maven ==== | ||
+ | |||
+ | === Useful maven resources=== | ||
+ | |||
+ | ^What ^Where ^ | ||
+ | |Maven variables |Listed [[http:// | ||
+ | |||
+ | |||
+ | |||
+ | === Glossary === | ||
+ | |||
+ | |Lifecycle|There is a predefined lifecycle. Maven executed all phases of this lifecycle \\ http:// | ||
+ | |Phase| Generate-sources, | ||
+ | |Goal|Goals are executed in phases. (test, jar, install). Goals are defined by plugins. Each executed plugin binds it's goals to predefined phases.| | ||
+ | |Mojo|Maven Plain Old Java Object. Each Mojo is a goal in maven| | ||
+ | |||
+ | === Phases === | ||
+ | * install - installiert in Lokale Repo | ||
+ | * deploy - installiert ins Nexus | ||
+ | |||
+ | |||
+ | === Goals and Phases === | ||
+ | |||
+ | {{http:// | ||
+ | |||
+ | |||
+ | == The Syntax to execute a phase == | ||
+ | < | ||
+ | |||
+ | Examples: | ||
+ | < | ||
+ | mvn clean | ||
+ | mvn deploy | ||
+ | mvn install | ||
+ | </ | ||
+ | |||
+ | **Achtung: | ||
+ | Executing: | ||
+ | < | ||
+ | mvn clean | ||
+ | </ | ||
+ | |||
+ | does | ||
+ | |||
+ | < | ||
+ | process-resources | ||
+ | compile | ||
+ | process-test-resources | ||
+ | test-compile | ||
+ | test | ||
+ | package | ||
+ | install | ||
+ | </ | ||
+ | |||
+ | |||
+ | == The Syntax to execute a goal == | ||
+ | < | ||
+ | mvn myplugin: | ||
+ | </ | ||
+ | |||
+ | Examples: | ||
+ | < | ||
+ | mvn jboss-as: | ||
+ | mvn dependency: | ||
+ | </ | ||
+ | |||
+ | You can mix up executing phases (e.g. clean or package) with goal-execution of some plugins (e.g. dependency: | ||
+ | Examples: | ||
+ | < | ||
+ | mvn clean dependency: | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | === Variables in pom.xml === | ||
+ | |||
+ | |${project.basedir}| main project directory | | ||
+ | |${project.parent.basedir}| parent pom's directory | | ||
+ | |${project.parent.parent.basedir}| grand parent pom's directory | | ||
+ | ==== Usage ==== | ||
+ | |||
+ | === Merging === | ||
+ | Child POMs override parent Pom's nodes on default. \\ | ||
+ | How to change this behaviour is described here: [[http:// | ||
+ | |||
+ | |||
+ | |||
+ | ==== Settings ==== | ||
+ | |||
+ | === java.lang.OutOfMemoryError === | ||
+ | To avoid this error during //mvn clean install// assign more space to Java. | ||
+ | Use an environment variable **MAVEN_OPTS** | ||
+ | < | ||
+ | set MAVEN_OPTS=-Xmx1024m | ||
+ | </ | ||
+ | |||
+ | ==== Abhängigkeiten visualisieren==== | ||
+ | |||
+ | ==Visualize on Console== | ||
+ | |||
+ | < | ||
+ | mvn dependency: | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==Visualize as PNG== | ||
+ | < | ||
+ | mvn org.fusesource.mvnplugins: | ||
+ | </ | ||
+ | |||
+ | {{http:// | ||
+ | |||
+ | |||
+ | |||
+ | < | ||
+ | < | ||
+ | xmlns: | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <!-- encrypted pass or api token from artifactory profile --> | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <!-- encrypted pass or api token from artifactory profile --> | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | Now you can add the following to your projects pom.xml | ||
+ | |||
+ | < | ||
+ | |||
+ | <project .... | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | # The following command deploys the artifact to the Artifactory. | ||
+ | < | ||
+ | mvn clean install | ||
+ | mvn clean deploy | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Version Vodoo ==== | ||
+ | |||
+ | == SNAPSHOT == | ||
+ | * The Word **SNAPSHOT** is interpreted by Maven, if it is contained inside the **version** string. | ||
+ | * The Word **SNAPSHOT** is interpreted during **install** or **deploy** phases. Inside the target folder the filename will still contain SNAPSHOT. After deploy it will be replaced. | ||
+ | * The Word **SNAPSHOT** is expanded to a qualifier, e.g. to date and time. | ||
+ | |||
+ | |||
+ | Example: | ||
+ | < | ||
+ | target: 1.0-SNAPSHOT | ||
+ | deploy: 1.0-20080207-230803-1 | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | == qualifier == | ||
+ | Frther there is an OSGI Version too. | ||
+ | It is called **qualifier**. It is replaced by a timestamp in maven plugins. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== Dependency Management and Scope ==== | ||
+ | Maven manages the dependencies transitively. | ||
+ | Here are the rules, about how maven resolves dependencies: | ||
+ | |||
+ | Scope is a concept, which allows to say, that dependency X is only available at runtime, or should not be inherited transitively. | ||
+ | |||
+ | Scopes: | ||
+ | |compile| This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, | ||
+ | |provided|This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.| | ||
+ | |runtime|This scope indicates that the dependency is not required for compilation, | ||
+ | |test|This scope indicates that the dependency is not required for normal use of the application, | ||
+ | |system|This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.| | ||
+ | |import|(only available in Maven 2.0.9 or later)This scope is only used on a dependency of type pom in the < | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==== Profiles ==== | ||
+ | |||
+ | Syntax to use the profile **jetty** | ||
+ | < | ||
+ | mvn clean install -P jetty | ||
+ | </ | ||
+ | |||
+ | == Plugins == | ||
+ | If you keep the a part of the xml-structure and insert the structure between the **< | ||
+ | |||
+ | Define some plugins which will only be used when profile **jetty** is enabled | ||
+ | < | ||
+ | <!-- profile to start jetty --> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | ... | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | == Properties == | ||
+ | |||
+ | You can use properties to configure the usual build | ||
+ | < | ||
+ | <project xmlns=" | ||
+ | xsi: | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | <!-- profile to start jetty will be packaged as pom --> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | ... | ||
+ | </ |