Maven pom distributionManagement configuration method
The function of distributionManagement is to "distribute components to remote repository".
mvn install will install the generated artifacts of the project to the local Maven repository.mvn deploy is used to distribute the generated artifacts of the project to the remote Maven repository。
The components of the local Maven warehouse can only be used by the current user. After being distributed to the remote Maven warehouse, all users who can access the warehouse can use your components.
We need to configure the distributionManagement of POM to specify the location of the Maven distribution artifact.
The role of <distributionManagement>: Responsible for managing the release of components. This is an environment variable.
1. Release of components
In the POM of the Maven project, the environment configuration <distributionManagement> is responsible for managing the release of components.
<distributionManagement> ... <downloadUrl>/my-project</downloadUrl> <status>deployed</status> </distributionManagement>
<downloadUrl> URL </downloadUrl> Other Maven projects can download and reference the components of the current Maven project through this URL.
<status> The current status of the Maven project.
There are several available states:
-
none
: The status is not specified, default value -
converted
: The artifacts of the Maven project have been converted to compatible with Maven 2 -
partner
: The artifacts of this Maven project remain consistent with the Maven version of another library -
deployed
: The components of this Maven project are published through Maven 2 or Maven 3, the most commonly used values -
verified
: The components of this Maven project have been verified
2. Push warehouse settings (commonly used)
2.1 <repository> <snapshotRepository> in <distributionManagement>
<distributionManagement> <repository> <uniqueVersion>false</uniqueVersion> <id>corp1</id> <name>Corporate Repository</name> <url>scp://repo/maven2</url> <layout>default</layout> </repository> <snapshotRepository> <uniqueVersion>true</uniqueVersion> <id>propSnap</id> <name>Propellors Snapshots</name> <url>sftp:///maven</url> <layout>legacy</layout> </snapshotRepository> ... </distributionManagement>
- <uniqueVersion> Specifies whether a unique version number is generated or the version part in the address is used.(true or false)
- <id> library id
- <name> library name
- <url> library's url
- <layout> default or legacy
2.2 The meanings of <repository> and <snapshotsrepository> in <distributionManagement>
The maven repository is divided into two types: release repository (<repository>) and snapshot snapshot repository (<snapshotsrepository>).
-
snapshot
Snapshot repository is used to save unstable versions during development. -
release
The official repository is used to save stable releases.
Define a component/module as a snapshot version. Just add -SNAPSHOT to the version number of the template in the pom file. Note: Must be capitalized.
maven will determine whether this is a snapshot version or a formal version based on whether the module's version number (<version> version number</version> in the pom file) contains -SNAPSHOT.
If it is a snapshot version:
- When mvn deploy is automatically published to the snapshot version library.
- For modules that use snapshot versions, when directly compiling and packaging without changing the version number, maven will automatically download the latest snapshot version from the mirror server.
If it is an official release version:
- Then it will be automatically published to the official version library when mvn deploy.
- When using the official version of the module, without changing the version number, if the module already exists locally, use the local version instead of actively downloading it on the mirror server when compiling and packaging.
3. Deploy websites and documents
The <distributionManagement>'s <site> configuration can also deploy the website and documents of the current Maven project in addition to deploying the components of the current Maven project.
Examples are as follows:
<distributionManagement> ... <site> <id></id> <name>Mojo Website</name> <url>scp:///home/projects/mojo/public_html/</url> </site> ... </distributionManagement>
4. Rename the component
As a Maven project grows, the artifacts of the Maven project may need to be republished to a new library.
<relocation> can publish the current Maven project to another library as a new artifact.
<distributionManagement> ... <relocation> <groupId></groupId> <artifactId>my-project</artifactId> <version>1.0</version> <message>We have moved the Project under Apache</message> </relocation> ... </distributionManagement>
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.