1, Using docker to build maven nexus private server
1: Download Image
docker pull sonatype/nexus3
2: create the mount directory and grant permissions to / var / lib / docker / volumes / nexus data
chmod 777 nexus-data/
3: start container
docker run -d -p 8081:8081 --name nexus -v /var/lib/docker/volumes/nexus-data:/nexus-data -v /etc/timezone:/etc/timezone -v /etc/localtime:/etc/localtime --restart=unless-stopped sonatype/nexus3
Connect to sonatype-download.global.ssl.fastly.net:443 exception may exist in the log after startup
Processing method: log in the account, open [System] -- [Capabilities], and disable [reach: management].
4: visit
The default password is admin123 or exists in / var / lib / docker / volumes / nexus data / admin.password
5: create warehouse
The warehouse types include hosted (the host warehouse stores the internal jar of the company), proxy (the proxy warehouse), group (the group warehouse contains hosted and proxy)
We need to create an agent warehouse http://maven.aliyun.com/nexus/content/groups/public/ And join the group
6: create account
Create a private service account of nexus and give corresponding permissions
2, maven configures nexus image
1: modify the setting.xml file
<servers> <server> <id>maven-public</id> <username>username</username> <password>password</password> </server> <server> <id>snapshots</id> <username>username</username> <password>password</password> </server> <server> <id>releases</id> <username>username</username> <password>password</password> </server> </servers> <profiles> <profile> <id>id</id> <activation> <jdk>1.8</jdk> <activeByDefault>true</activeByDefault> </activation> <repositories> <repository> <id>maven-public</id> <name>Nexus Public Repository</name> <url>http://ip:8081/repository/maven-public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> <repository> <id>releases</id> <name>Repository for haite</name> <url>http://ip:8081/repository/releases/</url> </repository> <repository> <id>snapshots</id> <name>Repository for haite</name> <url>http://ip:8081/repository/snapshots/</url> </repository> </repositories> <pluginRepositories> <!--Plug in library address--> <pluginRepository> <id>maven-public</id> <url>http://ip:8081/repository/maven-public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles>
< enabled > true < / enabled > used to enable the warehouse. The snapshot version is not enabled by default
2: when uploading jar to nexus, you need to add it in the pom file of the project
<distributionManagement> <repository> <id>releases</id> <name>Nexus Release Repository</name> <url>http://ip:8081/repository/releases/</url> </repository> <snapshotRepository> <id>snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://ip:8081/repository/snapshots/</url> </snapshotRepository> </distributionManagement>
Run maven's deploy command in the project to upload jar to nexus
Note:
1: only the snapshot warehouse is uploaded successfully, and the Release warehouse is not uploaded successfully. This is because there is snapshot at the end of the version number name. By default, it will not be uploaded to the Release warehouse at the end. If it is removed, it will be uploaded to the Release warehouse and will not be uploaded to the snapshot warehouse
2: the Release warehouse does not support repeated Release by default
3: note that the id under the server tag in setting should be the same as the warehouse configuration id in pom file, that is, specify which warehouse to upload to
3, maven common commands
1: upload jar
You can upload jar through nexus management interface, but only to relesae warehouse
You can also upload jar to nexus through the following command
mvn -X deploy:deploy-file -s settings.xml -Dmaven.test.skip=true -DgroupId=? -DartifactId=? -Dversion=? -Dpackaging=pom -Dfile=pom file -DpomFile=pom file -Durl=http://User name: password @ ip:8081/repository/snapshots mvn -X deploy:deploy-file -s settings.xml -Dmaven.test.skip=true -DgroupId=? -DartifactId=? -Dversion=? -Dpackaging=jar -Dfile=jar file -DpomFile=pom file -Durl=http://User name: password @ ip:8081/repository/snapshots mvn -X deploy:deploy-file -s settings.xml -Dmaven.test.skip=true -DgroupId=? -DartifactId=? -Dversion=? -Dpackaging=pom -Dfile=pom file -DpomFile=pom file -Durl=http://User name: password @ ip:8081/repository/releases -DrepositoryId=releases mvn -X deploy:deploy-file -s settings.xml -Dmaven.test.skip=true -DgroupId=? -DartifactId=? -Dversion=? -Dpackaging=jar -Dfile=jar file -DpomFile=pom file -Durl=http://User name: password @ ip:8081/repository/releases -DrepositoryId=releases
The above commands are to upload pom or jar to snapshots (development version) and releases (stable version), respectively