Skip to content

Instantly share code, notes, and snippets.

@jianhuabi
Forked from michaellihs/maven-cheatsheet.md
Created September 12, 2021 07:01
Show Gist options
  • Select an option

  • Save jianhuabi/8eed8c296b6419d5bd8a990c1eb909b5 to your computer and use it in GitHub Desktop.

Select an option

Save jianhuabi/8eed8c296b6419d5bd8a990c1eb909b5 to your computer and use it in GitHub Desktop.

Revisions

  1. @michaellihs michaellihs revised this gist Apr 14, 2017. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions maven-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -125,6 +125,11 @@ timeout(time:5, unit:'MINUTES') {
    }
    ````

    Artifactory Release Management
    ------------------------------

    see [https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Artifactory+Plugin+-+Release+Management](https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Artifactory+Plugin+-+Release+Management)


    Troubleshooting Maven
    =====================
  2. @michaellihs michaellihs revised this gist Apr 12, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion maven-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ My collection of useful hints and snippets for [Apache Maven](http://maven.apach
    POM - Project Object Model
    --------------------------

    See [http://maven. apache.org/pom.html](http://maven. apache.org/pom.html)
    See [http://maven.apache.org/pom.html](http://maven.apache.org/pom.html)

    ### Minimal POM

  3. @michaellihs michaellihs revised this gist Apr 12, 2017. No changes.
  4. @michaellihs michaellihs revised this gist Apr 12, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion maven-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -143,7 +143,7 @@ Problems with Maven Release Plugin
    </plugin>
    ```

    Maven does not upload relase version but SNAPSHOT
    Maven does not upload RELEASE version but SNAPSHOT
    -------------------------------------------------

    See [https://issues.apache.org/jira/browse/MRELEASE-812](https://issues.apache.org/jira/browse/MRELEASE-812).
  5. @michaellihs michaellihs revised this gist Apr 12, 2017. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion maven-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,13 @@ mvn help:effective-pom
    ### Parent POM Files

    * Used to **avoid redundancy**
    *

    Version Handling
    ----------------

    Set version in `<project><version>...</version></project>` from the command line with

    mvn versions:set versions:commit -DnewVersion=1.0.0-SNAPSHOT


    Maven Release Plugin
  6. @michaellihs michaellihs revised this gist Aug 19, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions maven-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -150,3 +150,4 @@ Further Resources
    * [DZone: Why I never use the Maven release plugin](https://dzone.com/articles/why-i-never-use-maven-release)
    * [Maven Release Plugin: The Final Nail in the Coffin](https://axelfontaine.com/blog/final-nail.html)
    * [Maven Cheat Sheet](https://confluence.sakaiproject.org/display/REL/Maven+release+plugin+cheat+sheet)
    * [About publishing Maven Artifacts](http://www.apache.org/dev/publishing-maven-artifacts.html#publish-snapshot)
  7. @michaellihs michaellihs revised this gist Aug 19, 2016. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion maven-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -46,6 +46,7 @@ mvn help:effective-pom
    ### Parent POM Files

    * Used to **avoid redundancy**
    *


    Maven Release Plugin
    @@ -146,4 +147,6 @@ Further Resources
    =================

    * [Book: Mastering Apache Maven 3](http://shop.oreilly.com/product/9781783983865.do)
    *
    * [DZone: Why I never use the Maven release plugin](https://dzone.com/articles/why-i-never-use-maven-release)
    * [Maven Release Plugin: The Final Nail in the Coffin](https://axelfontaine.com/blog/final-nail.html)
    * [Maven Cheat Sheet](https://confluence.sakaiproject.org/display/REL/Maven+release+plugin+cheat+sheet)
  8. @michaellihs michaellihs revised this gist Aug 19, 2016. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions maven-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -122,6 +122,20 @@ timeout(time:5, unit:'MINUTES') {
    Troubleshooting Maven
    =====================

    Problems with Maven Release Plugin
    ----------------------------------

    * Update your Git version
    * Make sure to have the most recent version of the plugin set in your `pom.xml`

    ```XML
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
    <version>2.5.3</version>
    </plugin>
    ```

    Maven does not upload relase version but SNAPSHOT
    -------------------------------------------------

  9. @michaellihs michaellihs revised this gist Aug 19, 2016. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions maven-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -119,6 +119,15 @@ timeout(time:5, unit:'MINUTES') {
    ````


    Troubleshooting Maven
    =====================

    Maven does not upload relase version but SNAPSHOT
    -------------------------------------------------

    See [https://issues.apache.org/jira/browse/MRELEASE-812](https://issues.apache.org/jira/browse/MRELEASE-812).


    Further Resources
    =================

  10. @michaellihs michaellihs revised this gist Aug 19, 2016. 1 changed file with 8 additions and 14 deletions.
    22 changes: 8 additions & 14 deletions maven-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -4,12 +4,11 @@ Maven Cheat Sheet
    My collection of useful hints and snippets for [Apache Maven](http://maven.apache.org/).

    POM - Project Object Model
    ==========================
    --------------------------

    See [http://maven. apache.org/pom.html](http://maven. apache.org/pom.html)

    Minimal POM
    -----------
    ### Minimal POM

    ````xml
    <project>
    @@ -20,8 +19,7 @@ Minimal POM
    </project>
    ````

    Super POM
    ---------
    ### Super POM

    Bundled with Maven in `MAVEN_HOME/lib/maven-model-builder- 3.2.3.jar - org/apache/maven/model/pom-4.0.0.xml` - defines

    @@ -31,35 +29,31 @@ Bundled with Maven in `MAVEN_HOME/lib/maven-model-builder- 3.2.3.jar - org/apach
    * A `<reporting>` section
    * The default build profile

    Overriding Values in POM
    ------------------------
    ### Overriding Values in POM

    Define "blocks" with the same ID as in the Super POM. Show "effective" POM with

    ````shell
    mvn help:effective-pom
    ````

    Maven Coordinates
    -----------------
    ### Maven Coordinates

    * Identify a project, dependency or plugin
    * A combination of `groupId`, `artifact` and `version`
    * Plugins don't need a version, as a default, `org.apache.maven.plugins` or `org. codehaus.mojo` is used

    Parent POM Files
    ----------------
    ### Parent POM Files

    * Used to **avoid redundancy**


    Maven Release Plugin
    ====================
    --------------------

    The [Maven Release Plugin](http://maven.apache.org/maven-release/maven-release-plugin/) let's you upload artifacts to Maven repositories - e.g. Artifactory.

    Jenkins Pipeline for Uploading Maven Artifacts
    ----------------------------------------------
    ### Jenkins Pipeline for Uploading Maven Artifacts

    ````groovy
    stage 'Clone from Git'
  11. @michaellihs michaellihs revised this gist Aug 19, 2016. 1 changed file with 77 additions and 0 deletions.
    77 changes: 77 additions & 0 deletions maven-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,8 @@
    Maven Cheat Sheet
    =================

    My collection of useful hints and snippets for [Apache Maven](http://maven.apache.org/).

    POM - Project Object Model
    ==========================

    @@ -48,6 +53,78 @@ Parent POM Files
    * Used to **avoid redundancy**


    Maven Release Plugin
    ====================

    The [Maven Release Plugin](http://maven.apache.org/maven-release/maven-release-plugin/) let's you upload artifacts to Maven repositories - e.g. Artifactory.

    Jenkins Pipeline for Uploading Maven Artifacts
    ----------------------------------------------

    ````groovy
    stage 'Clone from Git'
    node {
    checkout scm
    }
    stage 'Build'
    node {
    sh 'mvn clean install -DskipTests'
    }
    stage 'Test'
    node {
    sh 'mvn test'
    }
    stage 'Upload to Artifactory'
    timeout(time:5, unit:'MINUTES') {
    input message: 'Do you want to push artifacts to Artifactory?'
    node {
    def pom = readMavenPom file: 'pom.xml'
    def version = pom.version.replace("-SNAPSHOT", ".${currentBuild.number}")
    /**
    * Clean any locally modified files and ensure we are actually on origin/master
    * as a failed release could leave the local workspace ahead of origin/master
    */
    sh "git clean -f && git reset --hard origin/master"
    /**
    * Description of parameters (for further details, see http://maven.apache.org/maven-release/maven-release-plugin/)
    *
    * -DreleaseVersion Default version to use when preparing a release or a branch.
    * -DdevelopmentVersion Default version to use for new local working copy
    * -DpushChanges Implemented with git will or not push changes to the upstream repository
    * -DlocalCheckout Use a local checkout instead of doing a checkout from the upstream repository
    * -DpreparationGoals Goals to run as part of the preparation step, after transformation but before committing
    * -Darguments="-DskipTests" Skips the tests in the release goal - see http://stackoverflow.com/questions/8685100/how-can-i-get-maven-release-plugin-to-skip-my-tests
    * -B Run in non-interactive (batch) mode
    *
    * Preparation steps:
    *
    * release:prepare see http://maven.apache.org/maven-release/maven-release-plugin/prepare-mojo.html
    * release:perform see http://maven.apache.org/maven-release/maven-release-plugin/perform-mojo.html
    */
    sh """mvn \
    -DreleaseVersion=${version} \
    -DdevelopmentVersion=${pom.version} \
    -DpushChanges=false \
    -DlocalCheckout=true \
    -DpreparationGoals=initialize \
    -Darguments="-DskipTests" \
    release:prepare release:perform \
    -B"""
    sh "git push origin ${pom.artifactId}-${version}"
    }
    }
    ````


    Further Resources
    =================

  12. @michaellihs michaellihs revised this gist Aug 19, 2016. 1 changed file with 20 additions and 1 deletion.
    21 changes: 20 additions & 1 deletion maven-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -33,4 +33,23 @@ Define "blocks" with the same ID as in the Super POM. Show "effective" POM with

    ````shell
    mvn help:effective-pom
    ````
    ````

    Maven Coordinates
    -----------------

    * Identify a project, dependency or plugin
    * A combination of `groupId`, `artifact` and `version`
    * Plugins don't need a version, as a default, `org.apache.maven.plugins` or `org. codehaus.mojo` is used

    Parent POM Files
    ----------------

    * Used to **avoid redundancy**


    Further Resources
    =================

    * [Book: Mastering Apache Maven 3](http://shop.oreilly.com/product/9781783983865.do)
    *
  13. @michaellihs michaellihs revised this gist Aug 17, 2016. 1 changed file with 22 additions and 1 deletion.
    23 changes: 22 additions & 1 deletion maven-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,8 @@ POM - Project Object Model

    See [http://maven. apache.org/pom.html](http://maven. apache.org/pom.html)

    Minimal POM:
    Minimal POM
    -----------

    ````xml
    <project>
    @@ -13,3 +14,23 @@ Minimal POM:
    <version>1.0.0</version>
    </project>
    ````

    Super POM
    ---------

    Bundled with Maven in `MAVEN_HOME/lib/maven-model-builder- 3.2.3.jar - org/apache/maven/model/pom-4.0.0.xml` - defines

    * Maven central repository
    * Maven central plugin repository
    * Required information to build a project in `<build>`
    * A `<reporting>` section
    * The default build profile

    Overriding Values in POM
    ------------------------

    Define "blocks" with the same ID as in the Super POM. Show "effective" POM with

    ````shell
    mvn help:effective-pom
    ````
  14. @michaellihs michaellihs created this gist Aug 17, 2016.
    15 changes: 15 additions & 0 deletions maven-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    POM - Project Object Model
    ==========================

    See [http://maven. apache.org/pom.html](http://maven. apache.org/pom.html)

    Minimal POM:

    ````xml
    <project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.packt</groupId>
    <artifactId>sample-one</artifactId>
    <version>1.0.0</version>
    </project>
    ````