Docker builds maven private server

Docker image docker-nexus3

1. Create a data volume to persist the data in the container to ensure that the data in the private server still exists after the container is deleted and rebuilt
$ docker volume create --name nexus-data


2. Start nexus
$ docker run -d -p 8081:8081 --name nexus -v nexus-data:/nexus-data sonatype/nexus3


3. After the startup is completed, you can access



it
  • maven-central is a proxy warehouse. When the dependencies we need do not exist on the private server, this warehouse will be downloaded directly from the maven central warehouse and cached in the private server.
  • maven-public is a repository group, which contains maven-releases, maven-snapshots and maven-central. Our newly created repository needs to be added to the maven-public group, so that people who use this private server only need to configure a maven- The public mirror can use all the dependencies in the private server
  • maven-releases and maven-snapshots correspond to releases and snapshots respectively


4. The default user of nexus is admin/admin123. It is recommended to change the password after startup, create a user specially for developers, and assign permissions to read and browse all repositories.

5. Use maven private server
for all projects of developers. To build a private server, you need to add the following configuration files to the .m2 directory


<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <servers>
    <server>
      <id>public</id>
      <username>dev</username>
      <password>dev222</password>
    </server>
  </servers>

  <mirrors>
    <mirror>
      <id>public</id>
      <mirrorOf>central</mirrorOf>
      <name>internal nexus repository</name>
      <url>http://IP:Port/repository/maven-public/</url>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>jdk-1.8</id>

      <activation>
	<activeByDefault>true</activeByDefault>
	<jdk>1.8</jdk>
      </activation>
      <properties>
	<maven.compiler.source>1.8</maven.compiler.source>
	<maven.compiler.target>1.8</maven.compiler.target>
	<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
      </properties>
    </profile>
    <profile>
	    <id>snapshots</id>
            <activation>
		<activeByDefault>true</activeByDefault>
	    </activation>
	     <repositories>
        	<repository>
             	    <id>public</id>
            	     <url>http://IP:PORT/repository/maven-public/</url>
               	     <releases>
               	       <enabled>true</enabled>
            	     </releases>
               	     <snapshots>
                       <enabled>true</enabled>
                      </snapshots>
       		 </repository>
 	      </repositories>
	</profile>
  </profiles>
</settings>



Note that dev is a newly created user. This user only has the permission to browse and read the dependent jar package on the private server. For users who need to upload files to the private server, the following configuration is required. <servers in the setting.xml file
under .m2 Add the following configuration segment to >tag
<server>
      <id>xxxxx-releases</id>
      <username>admin</username>
     <password>admin123</password>
     </server>
     <server>
      <id>xxxxx-snapshots</id>
      <username>admin</username>
     <password>admin123</password>
     </server>

Among them, xxxx-releases and xxxxx-snapshots are the newly created maven warehouses, and they are set to upload mode. There are two formats for
uploading to the private server
. 1. Upload 
the corresponding pom.xml file in the project through pom.xml, and append the following configuration section
<distributionManagement>
		<repository>
			<id>xxxxx-releases</id>
			<name>xxxxx-releases</name>
			<url>http://IP:Port/repository/xxxxx-releases/</url>
		</repository>
		<snapshotRepository>
			<id>xxxxx-snapshots</id>
			<name>xxxxx-snapshots</name>
			<url>http://IP:Port/repository/xxxxx-snapshots/</url>
		</snapshotRepository>
	</distributionManagement>

The id configured here needs to be consistent with the id of the server in setting.xml. After that, you can execute mvn deploy in the project directory and publish the jar to the warehouse of the private server. The jar ending with snapshots will be automatically published to xxxxx-snapshots , none will be released directly to xxxxx-releases

2. Use the command line to upload third-party jars
mvn -X deploy:deploy-file -DgroupId=com.chengf -DartifactId=test -Dversion=1.0.0 -Dpackaging=jar -Dfile=test.jar -Durl=http://IP:Port/repository/xxxxx-releases/ -DrepositoryId=xxxxx-releases

The repositoryId here needs to be consistent with the server id in setting.xml

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326702712&siteId=291194637