본문 바로가기

Dev

Maven Build lifecycle and POM version SNAPSHOT

728x90

Maven


http://maven.apache.org/guides/index.html



Build lifecycle


  • validate - validate the project is correct and all necessary information is available
  • compile - compile the source code of the project
  • test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  • package - take the compiled code and package it in its distributable format, such as a JAR. (into "target" folder)
  • integration-test - process and deploy the package if necessary into an environment where integration tests can be run
  • verify - run any checks to verify the package is valid and meets quality criteria
  • install - install the package into the local repository, for use as a dependency in other projects locally
  • deploy - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

  • These build phases (plus the other build phases not shown here) are executed sequentially to complete the default lifecycle. Given the build phases above, this means that when the default lifecycle is used, Maven will first validate the project, then will try to compile the sources, run those against the tests, package the binaries (e.g. jar), run integration tests against that package, verify the package, install the verifed package to the local repository, then deploy the installed package in a specified environment.


    http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference





    POM


    version

    The "SNAPSHOT" term means that the build is a snapshot of your code at a given time.

    It usually means that the version is a version still under heavy development.


    The three others answers provide you a good vision of what a -SNAPSHOT version is. I just wanted to add some information regarding the behavior of Maven when it finds a SNAPSHOT dependency.

    When you build an application, Maven will search for dependencies in the local repository. If a stable version is not found there, it will search the remote repositories (defined in settings.xml or pom.xml) to retrieve this dependency. Then, it will copy it into the local repository, to make it available for the next builds.

    For example, a foo-1.0.jar library is considered as a stable version, and if Maven finds it in the local repository, it will use this one for the current build.

    Now, if you need a foo-1.0-SNAPSHOT.jar library, Maven will know that this version is not stable and is subject to changes. That's why Maven will try to find a newer version in the remote repositories, even if a version of this library is found on the local repository. However, this check is made only once per day. That means that if you have a foo-1.0-20110506.110000-1.jar (i.e. this library has been generated on 2011/05/06 at 11:00:00) in your local repository, and if you run the Maven build again the same day, Maven will not check the repositories for a newer version.

    Maven provides you a way to can change this update policy in your repository definition:

    <repository>
        <id>foo-repository</id>
        <url>...</url>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>XXX</updatePolicy>
        </snapshots>
    </repository>

    where XXX can be:

    • always: Maven will check for a newer version on every build;
    • daily, the default value;
    • interval:XXX: an interval in minutes (XXX)
    • never: Maven will never try to retrieve another version. It will do that only if it doesn't exist locally. With the configuration, SNAPSHOT version will be handled as the stable libraries.

    (model of the settings.xml can be found here)


    from http://stackoverflow.com/questions/5901378/what-exactly-is-a-maven-snapshot-and-why-do-we-need-it