Spring Boot Multi-module and Maven private Warehouse

Source: Internet
Author: User
Tags aliyun

Objective

The system is complex, and it is almost necessary to extract the module from a single function, and to maintain multiple projects, it is almost necessary to extract the private warehouse management from the public package. The advantages do not need to be mentioned, the following will record the operation process.

1. Multi-module splitting

In. NET because of its unity, it is more natural to achieve. Spring Boot Building Multi-module engineering with Maven is no hassle, if my project contains the following packages:

I need to split them separately into separate modules, first to change the pom.xml,packaging type in the root directory to Pom, and add the modules node:

<?xmlVersion= "1.0" encoding= "UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">    <modelVersion>4.0.0</modelVersion>    <groupId>Com.youclk.multi-package</groupId>    <artifactId>Parent</artifactId>    <version>0.0.1-snapshot</version>    <modules>        <module>Api</module>        <module>Service</module>        <module>Dao</module>    </modules>    <packaging>Pom</packaging>    <parent>        <groupId>Org.springframework.boot</groupId>        <artifactId>Spring-boot-starter-parent</artifactId>        <version>1.5.10.RELEASE</version>        <relativePath/> <!--lookup parent from repository --    </parent>    <properties>        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>        <java.version>1.8</java.version>        <lombok>1.16.20</lombok>    </properties>    <dependencies>        <dependency>            <groupId>Org.springframework.boot</groupId>            <artifactId>Spring-boot-starter-test</artifactId>            <scope>Test</scope>        </dependency>        <dependency>            <groupId>Org.projectlombok</groupId>            <artifactId>Lombok</artifactId>            <version>${lombok}</version>        </dependency>    </dependencies></project>

Then create a new Module to port the corresponding code:

It is important to note that the startup class needs to be specified in the Pom.xml of the boot module:

<BUILD>         <PLUGINS>             <PLUGIN>  <GROUPID>  org.springframework.boot</GROUPID>  <ARTIFACTID>  spring-boot-maven-plugin</ARTIFACTID>  <CONFIGURATION>  <MAINCLASS>  Com.youclk.multipackage.api. Multiapplication</MAINCLASS>  <LAYOUT>  zip</LAYOUT>  </CONFIGURATION>  </pl Ugin>  </PLUGINS>  </BUILD>   

Unified Upgrade Version command: mvn versions:set -DnewVersion=0.0.1-SNAPSHOT This is almost done, and the reference is consistent with the normal dependency package:

<dependency>    <groupId>com.youclk.multi-package</groupId>    <artifactId>service</artifactId>    <version>0.0.1-SNAPSHOT</version></dependency>
2. NEXUS3 Private Warehouse Building

In the Docker era everything became incredibly simple, with Compose configured as follows:

version: ' 3.5 'Services:  Nexus:    Image:sonatype/nexus3:3.10.0Networks:      -Proxy-Youclkvolumes:      - /mnt/nas/db/nexus-data:/nexus-dataDeploy:      mode:ReplicatedLabels:        -Com.df.notify=true-com.df.port=8081-Com.df.servicedomain=nexus.youclk.comRestart_policy:        Condition:Anymax_attempts:3Update_config:        Delay:5sOrder:Start-firstResources:        Limits:          CPUs: ' 0.50 '          Memory:1gNetworks:  Proxy:    external:TrueYOUCLK:    external:True

The boot process takes about a minute:

Note that if your SSL is on a load balancer or other reverse proxy, then you must specify the X-forwarded-proto transport protocol as HTTPS in the HTTP header, and then you will be able to play happily.

3. Upload and Reference 3.1 upload

First you need to create a private warehouse in the Nexus, for example my:

Next, add the server node in the local Maven settings, by default ~/.m2/settings.xml :

<servers>  <server>       <id>youclk</id>       <username>admin</username>    <password>youclk</password>     </server></servers>

Add upload address in Pom.xml:

<DISTRIBUTIONMANAGEMENT>  < Repository>,  <ID>  nexus</ID>  <NAME>  releases repository</NAME>  <url> https://nexus.youclk.com/repository/youclk-releases/</URL>   <SNAPSHOTREPOSITORY>  <ID>  Nexus</ID>  <NAME>  Snapshot Repository </NAME>  <URL>  https://nexus.youclk.com/repository/youclk-snapshots/</ Url>,  </SNAPSHOTREPOSITORY>  </distributionmanagement  

The final execution mvn clean deploy is uploaded to the private repository, and the individual packet commands are as follows:

mvn deploy:deploy-file -DgroupId=com.youclk -DartifactId=utils -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar -Dfile=target/utils-0.0.1-SNAPSHOT.jar -Durl=https://nexus.youclk.com/repository/youclk/ -DrepositoryId=youclk

Manage and view:

3.1 References

Finally, the last is how to use the ~ if you need a global reference, you need to add and activate the warehouse in Settings.xml:

<?xmlVersion= "1.0" encoding= "UTF-8"?>  <settings>    <mirrors>          <mirror>            <id>Aliyun</id>            <mirrorOf>Central</mirrorOf>            <name>Central Mirror</name>            <url>Http://maven.aliyun.com/mvn/repository</url>        </mirror>        <mirror>            <id>Nexus</id>            <mirrorOf>Maven-public</mirrorOf>            <name>Private mirror</name>            <url>http://local-nexus.youclk.com/repository/maven-public/</url>        </mirror>    </mirrors>         <servers>        <server>               <id>Nexus</id>               <username>Admin</username>            <password>Youclk</password>           </server>    </servers>     <profiles>          <profile>              <id>Nexus</id>               <repositories>                  <repository>                      <id>Maven</id>                      <name>Local private Nexus</name>                      <url>http://local-nexus.youclk.com/repository/maven-public/</url>                      <releases>                          <enabled>True</enabled>                      </releases>                      <snapshots>                          <enabled>True</enabled>                      </snapshots>                  </repository>              </repositories>                              <pluginRepositories>                  <pluginRepository>                      <id>Maven</id>                      <name>Local private Nexus</name>                      <url>http://local-nexus.youclk.com/repository/maven-public/</url>                      <releases>                          <enabled>True</enabled>                      </releases>                      <snapshots>                          <enabled>True</enabled>                      </snapshots>                  </pluginRepository>              </pluginRepositories>          </profile>    </profiles>      <activeProfiles>          <activeProfile>Nexus</activeProfile>      </activeProfiles>   </settings>  

However, generally not recommended, settings.xml should be kept as concise as possible, thin configuration, here leave the agent and authorization authentication, the rest can be ported to Pom.xml:

<repositories>    <repository>        <id>Aliyun</id>        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>    </repository>    <repository>        <id>Nexus</id>        <url>http://local-nexus.youclk.com/repository/maven-public/</url>    </repository></repositories><pluginRepositories>    <pluginRepository>        <id>Central</id>        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>    </pluginRepository>    <pluginRepository>        <id>Maven-public</id>        <url>http://local-nexus.youclk.com/repository/maven-public/</url>    </pluginRepository></pluginRepositories>
Summary

Recently opened a subscription number, have already seen here, and then by the way to pay attention to Bai ~ engraved, we grow together, wish Bin:)

Spring Boot Multi-module and Maven private Warehouse

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.