Build Maven private service (Nexus)

1. Download and install

URL: http://www.sonatype.org/nexus/go/

Download package: nexus-2.12.0-01-bundle.tar.gz
Extract package: tar -zxvf nexus-2.12.0-01-bundle.tar.gz The
default port is 8081, if you need to modify it, please check the configuration file conf/nexus .properties 
itself is not recommended to be used under the root user. If we need to start the service under the root user, we must first configure RUN_AS_USER=root in the bin/nexus file

Second, the startup and configuration of private servers

start up

[root@localhost nexus-maven]# cd nexus-2.12.0-01/bin/
[root@localhost bin]# ./nexus start
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Starting Nexus OSS...
Started Nexus OSS.
[root@localhost bin]# ./nexus status
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Nexus OSS is running (34504).
[root@localhost bin]#

Visit the home page after startup:  http://192.168.19.130:8081/nexus/index.html

Login default account/password admin/admin123
 

2. Open Repositories and set Download Remote Indexes in the Configuration of all projects whose Type is proxy in the list to True 

3. Set the Deployment Policy of the Releases repository to *Allow ReDeploy

4. Set the deployment account password

 

5. Right-click on the Central warehouse and click Repair Index to download the index file of the central warehouse. After a while, you can click Browse Index below to see the downloaded index file.

Of course, we can't avoid using some third-party jars, and these jar packages do not exist in the maven central repository on the Internet. At this time, we can manually add jars to our private server.
Add third-party jars as follows:

If you need to delete, as follows :)

3. Local project configuration reference private server

Configure the private library address in the project's pom.xml, and add it below the pom.xml:

    <!-- 私有仓库 -->
    <repositories>  
        <repository>  
            <id>public</id>  <!--这个ID需要与你的组group ID一致--> 
            <name>Public Repository</name>
            <url>http://192.168.19.130:8081/nexus/content/groups/public</url>   
        </repository>  
    </repositories> 

    <!-- 打包发布 -->
    <distributionManagement>
        <repository>
            <id>releases</id><!--这个ID需要与你的release仓库的Repository ID一致-->
            <url>http://192.168.19.130:8081/nexus/content/repositories/releases</url>
        </repository>

        <snapshotRepository>
            <id>snapshots</id><!--这个ID需要与你的snapshots仓库的Repository ID一致-->
            <url>http://192.168.19.130:8081/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

Configure server account information in settings.xml:

  <servers>
     <server>
        <id>releases</id>
        <username>deployment</username>
        <password>dev123</password><!--这个密码就是你设置的密码-->
    </server>
    <server>
        <id>snapshots</id>
        <username>deployment</username>
        <password>dev123</password><!--这个密码就是你设置的密码-->
    </server>
  </servers>

One thing to note:
When both the releases repository and the snapshots repository are configured in pom.xml.
The version configuration 1.0.0-SNAPSHOT at the beginning of the pom.xml file is built to the snapshots library, and
the version configuration 1.0.0 (without -SNAPSHOT) at the beginning of the pom.xml file will be built to the releases library.
If only the releases library is configured, the The version number is written with -SNAPSHOT, and a 400 error will be reported at the last step of the build because it cannot find the corresponding library.

4. Test

1. Create a new simple maven project and write a class casually.
In the pom.xml file  ,  add a private repository and package release configuration by referring to the private server method in the above three, local project configuration,
and then use the command mvn deploy to publish successfully. At this time, we can see the result after publishing in our private server, as follows:

2. Create a new project, or use an existing maven project (it is best to use a computer with a different environment).
In pom.xml, as in step 1, configure the private library address first, and then add the dependency published in step 1, and you can see that the jar is loaded into the project normally.

References

https://yq.aliyun.com/articles/7427

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325330850&siteId=291194637