Maven version number terrible secret hidden

This article is reproduced in: https://www.cnblogs.com/hafiz/p/8124741.html

One, background

  Now the mainstream Java-based Internet company, as the vast majority of companies use Maven dependency management tool, we generally rely on the version number for the common two types: one with "-RELEASE" at the end, and the other with "- SNAPSHOT "at the end. You do not look a little difference, but hidden inside this huge secret: When we developed teamwork, depends upon naming the version number is not very standard, then, a phenomenon often you will find that others update a dependent, has been submitted to the PW, but you do not pull down the local life and death, and finally no way you chose to delete the local version of warehouses dependence, then the perfect solution. But have you ever think about why this happens? Is there a more efficient solution? Then this article we will talk about this.

Second, the principle and solutions

  PW in the enterprise, there will be releases snapshot snapshot repository and release issued warehouse, warehouse for unstable snapshot snapshot saved version of the development process, the official release warehouse is used to preserve stability.

  maven based on the version number (version pom file) module with or without "-SNAPSHOT" (Note that there must be upper case) to determine the snapshot version or the official version. If the version is a snapshot, it is automatically published to the PW snapshot repository when mvn deploy; if it is officially released version, you will be automatically posted to the official repository when mvn deploy.

  If in a project, we rely on a snapshot version of the module A, but also on the official version of the module B, then rely on the module without changing the version number, we conduct compiler package directly to the project: even if the local warehouse already there is a corresponding version dependent module a, maven or will automatically download the latest version dependency module a snapshot from the mirror server. And rely on the official version of the module B, if the local version of the already existing warehouse module B, maven will not take the initiative to download on the mirror server. This is why we will see in the local repository snapshot version-dependent directory of a jar with a time stamp, such as the following:

We know these later, how to solve this problem?

1. profits resolve (not elegant, it is not recommended)

  PW arranged locally directly maven configuration file, add the following configuration red box

<profile>
    <id>nexus</id>
    <repositories>
        <repository>
            <id>nexus</id>
            <name>Nexus</name>
            <url>http://localhost:8087/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>nexus</id>
            <name>Nexus</name>
            <url>http://localhost:8087/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
</profile>

2. When packing plus "-U" argument to force pulls all the latest code-dependent

  mvn clean install -U

3. semantic version

  First of all, we are in the team, to define dependent on good development must not forget to upgrade the version number, then the development process but also to maintain version number "-SNAPSHOT" at the end. Come to rely on the development as a snapshot version, so that every time someone else has updated later uploaded to the PW, it will automatically pull the latest code when you packaged locally, so as to facilitate our development and maintenance.

Third, the summary

  In this article, we will understand why the snapshot version dependencies, maven compiler package when there is no matter whether local, PW will go to pull the latest, while the official version of dependency, if the local repository already exists, maven not going to pull PW the latest reason, so we have to be based on a snapshot version of the development, but must remember that when the line becomes the official version, or if another function being developed locally, submitted to PW code is likely to be mistaken on the line. So far we have the perfect solution to the problem we throw the beginning of the article, and not profits resolved. I met a problem, I like to get in the end inquisitor, to solve the most complex problems in the most elegant way. About Maven, I want to say is: Getting Started very simple, but difficult proficient!

Guess you like

Origin www.cnblogs.com/JonaLin/p/11090745.html