Maven Private Warehouse-Nexus3 Tutorial

Maven private warehouse - Nexus3

  • During work, it may be necessary to encapsulate some common tool libraries
  • However, the company code is more sensitive and generally cannot be opened to public warehouses
  • At this time, you can use Nexus3 to build a private warehouse for internal use in the company
  • Video version: BiliBili

Demo steps

  1. Create Nexus3 service using docker
  2. Create project and push repository
    • Modify the project pom.xml file configuration
    • Modify Maven software configuration
    • Use the "mvn deploy" command to push to the warehouse
  3. Create a project and reference the project from the previous step
    • Modify Maven software configuration
    • Restart the IDE
    • Use the "mvn install" command to install dependencies

1. Use docker to create nexus3 service

  • Use docker to create a nexus3 container
    • Access: http://127.0.0.1:8081
    • It consumes more resources, and the startup speed is slower. If it shows that the page cannot be accessed, wait a little longer (it may take three to five minutes for computer scum, such as mine)
docker run -d -p 8081:8081 --name nexus sonatype/nexus3
  • get nexus3 password

    • Click "Sign in" in the upper right corner of the page, and follow the prompts in the pop-up window to find the default password
      • Default account: admin
      • Default password: "/nexus-data/admin.password" inside the container
      • You will be prompted to reset the password, change the password you remember (or use the default password), and you will need to use it later in the configuration
  • As shown in the figure below, copy the "maven-releases"/"maven-snapshots" warehouse address

nexus.png

  • nexus-public is a warehouse group, which contains the following warehouses by default
    • maven-releases: local release library
    • maven-snapshots: local snapshots library
    • maven-central: Proxy central maven library, can be changed to domestic proxy, such as Alibaba Cloud ( maven.aliyun.com/repository/… )

2. Create a project and push the warehouse

Modify the project pom.xml file configuration

  • Transform the Maven project directly (or create a new Maven project)
    • Execute "mvn package" to package jar projects
    • Add nexus3 address information in pom.xml as follows
      • Same level as dependencies/build
    <dependencies>...略</dependencies>
    <build>...略</build>

    <distributionManagement>
        <repository>
            <id>maven-releases</id>
            <name>maven-releases</name>
            <url>${这里填写从nexus页面上复制的maven-releases的url}</url>
        </repository>
        <snapshotRepository>
            <id>maven-snapshots</id>
            <name>maven-snapshots</name>
            <url>${这里填写从nexus页面上复制的maven-snapshots的url}</url>
        </snapshotRepository>
    </distributionManagement>
  • push package
    • Execute "mvn deoloy"
    • At this time, an error "...status: 401 Unauthorized" is reported, indicating that the project configuration is correct

Modify Maven software configuration

  • Open ${maven root directory}/conf/settings.xml
    • Add nexus account password
    • The id should be consistent with the one configured in the project pom.xml
<servers>
    <server>
        <id>maven-releases</id>
        <username>admin</username>
        <password>${密码}</password>
    </server>
    <server>
        <id>maven-snapshots</id>
        <username>admin</username>
        <password>${密码}</password>
    </server>
</servers>
  • Executing "mvn deploy" again will not report an error
    • Refresh the nexus page to see the uploaded package
      • Project release without "-SNAPSHOT" in "maven-releases" directory
      • Otherwise in the "maven-releases" directory

3. Create a project and reference the project code from the previous step

Modify Maven software configuration

  • Open ${maven root directory}/conf/settings.xml
    • Enable mirroring, comment out if there are other mirroring
  • Restart the IDE, add dependency in pom.xml like an online library to use
<mirror>
    <id>nexus-public</id>
    <mirrorOf>*</mirrorOf>
    <name>私有仓库</name>
    <url>${这里填写从nexus页面上复制的maven-public的url}</url>
</mirror>

References


ref: Maven Private Warehouse-Nexus3 - Nuggets

おすすめ

転載: blog.csdn.net/qq_34626094/article/details/130186609