===== 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, which are uniquely identified by: groupId, artifactId, version. - Maven artifacts can depend on other Maven artifacts. - Maven downloads required artifacts, which the local artifacts depend from - all into one local repository: C:\Users\\.m2 - Maven has an own Project type in Eclipse. Each Maven Project is a Maven artifact. ^What ^Where^ | 1. General "what is maven" description. | [[ http://maven.apache.org/guides/getting-started/index.html#What_is_Maven|What is maven?]] | | 2. Project requred fileds: groupId, artifactId, version | [[http://maven.apache.org/pom.html#Maven_Coordinates| Requred fields]] | | 3. Maven Phases, and so the commands | [[http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html#Running_Maven_Tools|Maven phases]] | | 4. Further details about Maven | [[ http://maven.apache.org/guides/getting-started/index.html |maven.apache.org]] | ==== Maven ==== === Useful maven resources=== ^What ^Where ^ |Maven variables |Listed [[http://docs.codehaus.org/display/MAVENUSER/MavenPropertiesGuide|here]] \\ A more complete List is [[http://books.sonatype.com/mvnref-book/reference/resource-filtering-sect-properties.html|here]] | === Glossary === |Lifecycle|There is a predefined lifecycle. Maven executed all phases of this lifecycle \\ http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Built-in_Lifecycle_Bindings| |Phase| Generate-sources, compile, test-compile,..., install, deploy| |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://i.stack.imgur.com/ciktU.png}} == The Syntax to execute a phase == mvn phasename Examples: mvn clean mvn deploy mvn install **Achtung:** Executing a phase - executes all phases up to the executed phase! \\ Executing: mvn clean does process-resources compile process-test-resources test-compile test package install == The Syntax to execute a goal == mvn myplugin:myGoal Examples: mvn jboss-as:deploy mvn dependency:copy-dependencies You can mix up executing phases (e.g. clean or package) with goal-execution of some plugins (e.g. dependency:copy-dependencies) \\ Examples: mvn clean dependency:copy-dependencies package === 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://blog.sonatype.com/people/2011/01/maven-how-to-merging-plugin-configuration-in-complex-projects/|http://blog.sonatype.com/people/2011/01/maven-how-to-merging-plugin-configuration-in-complex-projects/]] ==== 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:tree -Dincludes="this.is.your.gorup.id:this.is.the.artifact.id" ==Visualize as PNG== mvn org.fusesource.mvnplugins:maven-graph-plugin:RELEASE:reactor {{http://i520.photobucket.com/albums/w327/schajtan/2015-04-08_13-45-15_zpsqji69pt1.png}} maven2-central-remote maven2-central-remote https://mydomain.com/artifactory/maven2-central-remote maven2-priv maven2-priv https://mydomain.com/artifactory/maven2-priv maven2-central-remote https://mydomain.com/artifactory/maven2-central-remote center https://repo1.maven.org/maven2/ jcenter https://jcenter.bintray.com bt bt true 111.122.3.44 9400 mydomain.com|*.mydomain.com maven2-priv username@domain.com XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX maven2-priv-snap username@domain.com XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Now you can add the following to your projects pom.xml maven2-priv https://domain.com/artifactory/maven2-priv/ false maven2-priv maven2-priv https://domain.com/artifactory/maven2-priv default false maven2-priv-snap maven2-priv https://domain.com/artifactory/maven2-priv default ... # 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: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope 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, those dependencies are propagated to dependent projects.| |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, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.| |test|This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.| |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 section. It indicates that the specified POM should be replaced with the dependencies in that POM's section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency. | ==== 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 **** tags. Define some plugins which will only be used when profile **jetty** is enabled jetty ... == Properties == You can use properties to configure the usual build 4.0.0 de.updatesite.customplugins.site de.updatesite updatesite ${package.method} pom ...