Apache Maven · PDF file...

Click here to load reader

  • date post

  • Category


  • view

  • download


Embed Size (px)

Transcript of Apache Maven · PDF file...

  • Apache Maven

    Péter Jeszenszky Faculty of Informatics, University of Debrecen

    [email protected]

    Last modified: February 23, 2021

    mailto:[email protected]

  • 2

    Apache Maven ● A software project management and comprehension

    tool with the following objectives: – Making the build process easy. – Providing a uniform build system. – Providing quality project information. – Providing guidelines and best practices for development. – Allowing transparent migration to new features.

    ● See: https://maven.apache.org/what-is-maven.html


  • 3


    ● Major features include the following: – Uniform build system – Dependency management – Distribution publication – Reporting and website creation

    ● See: Feature Summary https://maven.apache.org/maven-features.html


  • 4

    Characteristics (1)

    ● Convention over configuration – E.g., defines a standard project directory layout.

    ● Defines project lifecycles and lifecycle phases ● Declarative ● Modular and extensible architecture

    – All of its functionality is provided by plugins.

  • 5

    Characteristics (2) ● Although it is used mainly for Java projects, can be also used for other

    programming languages, such as: – C/C++:

    ● nar-maven-plugin https://maven-nar.github.io/ https://github.com/maven-nar/nar-maven-plugin

    ● Native Maven Plugin https://www.mojohaus.org/maven-native/native-maven-plugin/ https://github.com/mojohaus/maven-native

    – Kotlin: ● kotlin-maven-plugin https://kotlinlang.org/docs/reference/using-maven.html

    – Scala: ● scala-maven-plugin http://davidb.github.io/scala-maven-plugin/


    https://maven-nar.github.io/ https://github.com/maven-nar/nar-maven-plugin https://www.mojohaus.org/maven-native/native-maven-plugin/ https://github.com/mojohaus/maven-native https://kotlinlang.org/docs/reference/using-maven.html http://davidb.github.io/scala-maven-plugin/ https://github.com/davidB/scala-maven-plugin

  • 6

    Development ● Written in Java ● Free and open source software

    – Distributed under the Apache License 2.0. ● The current stable version is 3.6.3 (released on

    November 25, 2019) – See: Maven Releases History

    https://maven.apache.org/docs/history.html ● The next version will be 3.7 ● Repository: https://github.com/apache/maven

    https://maven.apache.org/docs/history.html https://github.com/apache/maven

  • 7


    ● Requires a JDK to be installed, not just a JRE! – JDK 7 or later is required.

    ● The JAVA_HOME environment variable must be set properly!

    ● Download the latest version of Apache Maven from here: https://maven.apache.org/download.html

    ● Installation consists of unpacking an archive and setting the PATH environment variable.


  • 8

    Installation (Linux) (1)

    ● If unpacked in the directory /opt/apache- maven-3.6.3, set the PATH environment variable as shown: – export PATH=/opt/apache-maven-3.6.3/bin:$PATH

    ● Hint: add the above command to the /etc/profile.d/maven.sh file in order to be automatically executed.

  • 9

    Installation (Linux) (2)

    ● Alternatively, Apache Maven can be installed via the SDKMAN! tool, executing the following command: sdk install maven

    ● For the installation instructions of SDKMAN! see: https://sdkman.io/install


  • 10

    Installation (Windows)

    ● If unpacked in the directory C:\Program Files\apache-maven-3.6.3 – Add the C:\Program Files\apache-maven- 3.6.3\bin directory to the PATH environment variable.

  • 11

    Verifying Successful Installation

    ● Execute one of the following two equivalent commands in the command line: – mvn –version – mvn -v

    ● If the installation was successful, you should see the following output:

    Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /home/jeszy/.sdkman/candidates/maven/current Java version: 15.0.2, vendor: Oracle Corporation, runtime: /home/jeszy/.sdkman/candidates/java/15.0.2-open Default locale: hu_HU, platform encoding: UTF-8 OS name: "linux", version: "5.1.5-050105-generic", arch: "amd64", family: "unix"

    Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /home/jeszy/.sdkman/candidates/maven/current Java version: 15.0.2, vendor: Oracle Corporation, runtime: /home/jeszy/.sdkman/candidates/java/15.0.2-open Default locale: hu_HU, platform encoding: UTF-8 OS name: "linux", version: "5.1.5-050105-generic", arch: "amd64", family: "unix"

  • 12

    IDE Integration (1) ● Eclipse: m2eclipse https://www.eclipse.org/m2e/

    – Update site: https://download.eclipse.org/technology/m2e/releases/latest/

    – The Indigo release of the Eclipse IDE for Java Developers is shipped together with m2eclipse (no installation is required).

    ● IntelliJ IDEA: Provides built-in Apache Maven support. – See: https://www.jetbrains.com/help/idea/maven.html

    ● Netbeans: Provides built-in Apache Maven support since version 6.7. – See: http://wiki.netbeans.org/Maven

    https://www.eclipse.org/m2e/ https://download.eclipse.org/technology/m2e/releases/latest/ https://www.jetbrains.com/help/idea/maven.html http://wiki.netbeans.org/Maven

  • 13

    IDE Integration (2)

    ● Visual Studio Code: Maven support is provided by the Maven for Java extension. – See:

    ● Maven for Java https://marketplace.visualstudio.com/items?itemName=vs cjava.vscode-maven

    ● Java Project Management in VS Code – Maven https://code.visualstudio.com/docs/java/java-project#_ma ven

    https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-maven https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-maven https://code.visualstudio.com/docs/java/java-project#_maven https://code.visualstudio.com/docs/java/java-project#_maven

  • 14

    Further Information ● Official documentation: https://maven.apache.org/guides/ ● Free electronic books (licenc: Creative Commons BY-

    NC-ND): https://www.sonatype.com/resources/ebooks – Maven by Example

    https://github.com/sonatype/maven-example-en – Maven: The Complete Reference

    https://github.com/sonatype/maven-reference-en – Repository Management with Nexus

    https://github.com/sonatype/nexus-book ● Mailing lists: https://maven.apache.org/mailing-lists.html

    https://maven.apache.org/guides/ https://www.sonatype.com/resources/ebooks https://github.com/sonatype/maven-example-en https://github.com/sonatype/maven-reference-en https://github.com/sonatype/nexus-book https://maven.apache.org/mailing-lists.html

  • 15

    Standard Directory Layout (1)

    ● Standard directory layout for projects: – Introduction to the Standard Directory Layout

    https://maven.apache.org/guides/introduction/introd uction-to-the-standard-directory-layout.html

    https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

  • 16

    Standard Directory Layout (2)











  • 17

    Usage (1)

    ● Execute the mvn --help or mvn -h command to display usage information and available command line options.

    ● Apache Maven accepts lifecycle phases (e.g., mvn package) and plugin goals (e.g., mvn site:run) as command line arguments. – Multiple number of such command line arguments can be

    supplied. – Further options can be passed as system properties in the

    form -Dname=value

  • 18

    Usage (2)

    ● Plugin goals can be specified in the form groupId:artifactId:version:goal – This syntax is required when a specific version of

    the plugin must be used or Apache Maven does not associate a prefix with the plugin.

    – Example: mvn org.codehaus.mojo:versions-maven- plugin:2.8.1:help

  • 19

    settings.xml (1)

    ● A configuration file that stores project independent settings. – The $M2_HOME/conf/settings.xml file

    provides global setting for all users. – Users can place an own settings.xml file in

    the .m2 directory of their home directory to override global settings.

    ● On Linux systems the path of this file is ~/.m2/settings.xml.

  • 20

    settings.xml (2)

    ● Reference: https://maven.apache.org/ref/current/maven-set tings/settings.html

    ● XML schema: http://maven.apache.org/xsd/settings-1.1.0.xsd

    https://maven.apache.org/ref/current/maven-settings/settings.html https://maven.apache.org/ref/current/maven-settings/settings.html http://maven.apache.org/xsd/settings-1.1.0.xsd

  • 21

    settings.xml (3)

    ● The effective-settings goal of the Maven Help Plugin displays the current configuration settings. – The mvn help:effective-settings command outputs a