maven
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| maven [2024/02/27 16:46] – [Misc] kalaschnikow | maven [2024/08/01 13:41] (current) – [Maven Getting Started Guide] kalaschnikow | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Apache Maven ====== | ||
| + | https:// | ||
| + | |||
| + | ===== Documentation ===== | ||
| + | |||
| + | ==== What is Maven? ==== | ||
| + | |||
| + | https:// | ||
| + | |||
| + | * POM = Project Object Model | ||
| + | * POM + Plugins | ||
| + | * Maven suggest guidelines for project directory layout | ||
| + | |||
| + | * Features of Maven | ||
| + | * simple project setup | ||
| + | * using across many projects | ||
| + | * => no ramp-up time for new developers | ||
| + | * dependency management | ||
| + | * repository of libs and metadata | ||
| + | * model-based builds | ||
| + | * JAR, WAR, ... | ||
| + | * release management and distribution publication | ||
| + | * For example: | ||
| + | * integration with SCMs (e.g. Git) | ||
| + | * releases based on a tag | ||
| + | * source ditribution | ||
| + | |||
| + | ==== Maven in 5 minutes ==== | ||
| + | |||
| + | https:// | ||
| + | |||
| + | < | ||
| + | mvn archetype: | ||
| + | </ | ||
| + | |||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * A plugin can be understood as a " | ||
| + | * this '' | ||
| + | * my-app | ||
| + | * pom.xml | ||
| + | * /src | ||
| + | * /main | ||
| + | * /java | ||
| + | * ... | ||
| + | * ... | ||
| + | * /test | ||
| + | * /java | ||
| + | * ... | ||
| + | * ... | ||
| + | |||
| + | * Build the project: | ||
| + | * '' | ||
| + | * '' | ||
| + | * When a phase is given, Maven executes every phase in the sequence up to and including the one defined. | ||
| + | * To use proper Java version, '' | ||
| + | * //Default// Maven build lifecycle: | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * Other build lifecycles (not in // | ||
| + | * '' | ||
| + | * '' | ||
| + | * Phases are actually mapped to underlying goals. The specific goals executed per phase is dependant upon the packaging type of the project. For example, package executes jar:jar if the project type is a JAR, and war:war if the project type is a WAR. | ||
| + | * An interesting thing to note is that phases and goals may be executed in sequence: | ||
| + | * '' | ||
| + | ==== Maven Getting Started Guide ==== | ||
| + | |||
| + | https:// | ||
| + | |||
| + | * Maven helps to manage: | ||
| + | * builds | ||
| + | * documentation | ||
| + | * reporting | ||
| + | * dependencies | ||
| + | * SCMs | ||
| + | * releases | ||
| + | * distribution | ||
| + | * How to make a first Maven project? | ||
| + | * archetypes = " | ||
| + | * '' | ||
| + | * Example: | ||
| + | * '' | ||
| + | * '' | ||
| + | * contains Project Object Model | ||
| + | * '' | ||
| + | * used for the names of project artifacts | ||
| + | * e.g. primary artifact (typically JAR): '' | ||
| + | * properties | ||
| + | * value placeholders accessible anywhere within a POM | ||
| + | * How do I compile my application sources? | ||
| + | * '' | ||
| + | * '' | ||
| + | * compile + execute unit tests | ||
| + | * '' | ||
| + | * compile unit tests (without executing) | ||
| + | * How do I create a JAR and install it in my local repository? | ||
| + | * '' | ||
| + | * packages JAR in " | ||
| + | * '' | ||
| + | * installs the JAR in the local repo (default: '' | ||
| + | * How do I use plugins? | ||
| + | * '' | ||
| + | * How do I add resources to my JAR? | ||
| + | * use standard directory layout | ||
| + | * ''/ | ||
| + | * -> goes to the root of JAR | ||
| + | * ''/ | ||
| + | * can be addressed in Java code for example as: | ||
| + | * '' | ||
| + | * How do I filter resource files? | ||
| + | * To reference a property which value will be known firstly at the build time use '' | ||
| + | * The value of such property can be defined in: | ||
| + | * pom.xml | ||
| + | * '' | ||
| + | * e.g. '' | ||
| + | * settings.xml | ||
| + | * '' | ||
| + | * e.g.'' | ||
| + | * external properties file | ||
| + | * system property | ||
| + | * How do I use external dependencies? | ||
| + | * '' | ||
| + | * each dependency entry defines at least: | ||
| + | * groupId | ||
| + | * artifactId | ||
| + | * version | ||
| + | * scope | ||
| + | * e.g. '' | ||
| + | * dependencies will be fetched from local repo (default: '' | ||
| + | * with command: '' | ||
| + | * if dependency is not in local repo, it will be fetched from a remote repo (by default Maven Central: https:// | ||
| + | * How do I deploy my JAR in my remote repository? | ||
| + | * configure repo URL in the '' | ||
| + | * authentication info in '' | ||
| + | * How do I build more than one project at once? | ||
| + | * ... | ||
| + | |||
| + | . . . | ||
| + | |||
| + | === The Build Lifecycle === | ||
| + | |||
| + | https:// | ||
| + | |||
| + | Three built-in build lifecycles: | ||
| + | * default | ||
| + | * The default lifecycle handles your project deployment | ||
| + | * clean | ||
| + | * the clean lifecycle handles project cleaning | ||
| + | * site | ||
| + | * the site lifecycle handles the creation of your project' | ||
| + | |||
| + | The full [[https:// | ||
| + | |||
| + | Default lifecycle: | ||
| + | |||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | ===== Misc ===== | ||
| + | |||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | |||
| + | * [[https:// | ||
