In the coding process, there are some common code modules, sometimes we do not want to copy to the rough reuse, because this can not only reflect the changes, but also not conducive to unified management. Here we use the Maven deploy approach to make generic modules into jar packages, publish to Nexus, and let other projects refer to them for reuse and management in a more concise and efficient way.
First: Maven settings <server> tags in the settings.xml file
<Server> <ID>Release</ID> <username>Admin</username> <Password>Admin123</Password> </Server> <Server> <ID>Snapshot</ID> <username>Admin</username> <Password>Admin123</Password> </Server>
The user name and password set here are the Nexus's login configuration
Second: Set in the project's Pom.xml file
<distributionmanagement> <Repository> <ID>Release</ID> <URL>http://192.168.1.123:8081/nexus/content/repositories/releases/</URL> </Repository> <snapshotrepository> <ID>Snapshot</ID> <URL>http://192.168.1.123:8081/nexus/content/repositories/snapshots/</URL> </snapshotrepository></distributionmanagement>
In this case, the URL is the nexus of the corresponding warehouse link address, after the completion of this step, has completed the release of the basic configuration required. " try command: mvn deploy"
Note that <id> in:<server> is consistent with <repository>, <snapshotRepository> <id>, when Maven is released, The user name password will be searched based on this ID to verify the login and upload the file.
Third: Release Flexibility configuration
MAVEN will determine if the version is-snapshot, and if so, publish it to the Snapshots warehouse, or publish it to the release warehouse. Here we can set the Pom.xml file in the
<groupId>Com.test</groupId><Artifactid>My-test</Artifactid><Packaging>Jar</Packaging><version>${project.release.version}</version><Properties> <java.version>1.8</java.version> <project.release.version>1.0-snapshot</project.release.version></Properties><Profiles> < Profile> <ID>Product</ID> <Properties> <project.release.version>1.0</project.release.version> </Properties> </ Profile></Profiles>
Description: Use the placeholder ${project.release.version} to control the version that needs to be published, MVN deploy-p product with the command, and release the 1.0 version of My-test to the releases library. If you use the command mvn deploy, the 1.0-snapshot version number is used by default, and the 1.0-snapshot version of My-test is published to the snapshots library.
Fourth: Issues encountered during the release
1. When deploying to the snapshot warehouse, the jar package takes a timestamp, which does not matter, MAVEN will automatically take the corresponding version of the latest jar package;
2.Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (Default-deploy) on Project My-test : Failed to deploy artifacts:could not transfer artifact...from/to release ...
When deploying to the release warehouse, the same version of the jar package cannot be submitted. The workaround is to modify the version number before committing.
3. Continuous update ...
MAVEN releases jar package to Nexus