Current location - Health Preservation Learning Network - Slimming men and women - Difference and Function between Snapshot Library and Publishing Library in maven
Difference and Function between Snapshot Library and Publishing Library in maven
In the process of using maven, we often have many public libraries in an unstable state during the development stage, which need to be modified and released at any time, maybe once a day, or even encounter bugs n times a day. We know that maven's dependency management is based on version management. For released artifacts, if the version number is the same, maven will not download them actively even if the components on our internal mirror server are newer than the local ones. If you do dependency management based on the officially released version in the development stage, you need to upgrade the version number of the component when you encounter this problem, but this obviously does not meet the requirements and the actual situation. But if it is based on the snapshot version, the problem will be solved spontaneously, and maven has prepared all this for us.

There are two kinds of warehouses in maven, snapshot warehouse and publishing warehouse. Snapshot snapshot warehouse is used to store unstable versions in the development process, and release formal warehouse is used to store stable release versions. To define a component/module as a snapshot version, just add -SNAPSHOT after the module version number in the pom file (note that it must be capitalized here), as shown below:

& ltgroupId & gtcc.mzone & lt/groupId & gt;

& ltartifactId & gtm 1 & lt; /artifact id & gt;

& lt/version & gt;. 1- snapshot & lt/version >

& lt packaging & gtjar & lt/ packaging & gt

Maven2 will judge whether it is a snapshot version or an official version according to whether there is a -SNAPSHOT in the version number of the module (the version in the pom file). If it is a snapshot version, mvn will be automatically published to the snapshot version library when it is deployed, while maven will automatically download the latest snapshot version from the mirror server when compiling and packaging the module that directly uses the snapshot version, without changing the version number. If the version is officially released, it will be automatically released to the official version library when MVN is deployed. However, if the official version module is used, it will not be downloaded from the mirror server actively when compiling and packaging, and the version number will not be changed.

Therefore, in the development stage, we can set the version of the public library as the snapshot version, and rely on components to reference the snapshot version for development. After the snapshot version of the public library is updated, we can download the new version without modifying the version number indicated in the pom file. We can directly execute related compiling and packaging commands in mvn, and download the latest snapshot library again, which is also convenient for our development.