docker指令如下:
docker run -d --name nexus3 --restart=always -p 8081:8081 -p 8082:8082 -p 8083:8083 -p 8084:8084 -v /Users/alistar/docker-data/nexus3:/nexus-data sonatype/nexus3
请确保 -v
前面的路径/Users/alistar/docker-data/nexus3
中,目录已存在。
如下是我的maven
的配置文件settings.xml
配置,请根据自己的实际情况修改,主要修改是:
localRepository
本地仓库ip
地址给一个参考如下:
<?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">
<!--本地的仓库-->
<localRepository>/Users/alistar/dev-tool/local-repository</localRepository>
<pluginGroups></pluginGroups>
<proxies></proxies>
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>maven-public</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>maven-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>maven-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>3rd-part</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>maven-central</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>maven-public</id>
<name>public</name>
<mirrorOf>central</mirrorOf>
<url>http://192.168.100.2:8081/repository/maven-public/</url>
</mirror>
<mirror>
<id>maven-releases</id>
<name>releases</name>
<mirrorOf>central</mirrorOf>
<url>http://192.168.100.2:8081/repository/maven-releases/</url>
</mirror>
<mirror>
<id>maven-snapshots</id>
<name>snapshots</name>
<mirrorOf>central</mirrorOf>
<url>http://192.168.100.2:8081/repository/maven-snapshots/</url>
</mirror>
<mirror>
<id>3rd-part</id>
<name>3rd-part</name>
<mirrorOf>central</mirrorOf>
<url>http://192.168.100.2:8081/repository/3rd-part/</url>
</mirror>
<mirror>
<id>maven-central</id>
<name>maven-central</name>
<mirrorOf>central</mirrorOf>
<url>http://192.168.100.2:8081/repository/maven-central/</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>nexus</id>
<repositories>
<repository>
<id>nexus</id>
<url>http://192.168.100.2:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<url>http://192.168.100.2:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
在pom.xml
中配置
<distributionManagement>
<repository>
<id>maven-releases</id>
<name>Nexus Release Repository</name>
<url>http://192.168.100.2:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>maven-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://192.168.100.2:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
这里额外补充下,如果是nexus2
,内容应该是:
<!--nexus2的上传-->
<distributionManagement>
<!--项目内部的 maven 服务器-->
<repository>
<id>releases</id>
<name>Releases</name>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<!--项目内部的快照版本-->
<snapshotRepository>
<id>snapshots</id>
<name>Snapshots</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
说实话,我看到好多教程都有这个东西,但是我也不知道这个有什么用处,就先记录下这个地方吧,以备不时之需。
前往maven中央仓库下载 indexer-cli-xxx.jar 解压工具包
下载离线索引文件
nexus-maven-repository-index.gz
nexus-maven-repository-index.properties
将3个文件放在同一目录下解压,并利用如下指令解压,解压后会放在当前文件夹index
这个目录下
java -jar indexer-cli-xxx.jar -u nexus-maven-repository-index.gz -d indexer
请注意你下载时候当前版本号。
拷贝索引
将index
目录拷贝到/sonatype-work/nexus3/blobs/default
下。
稍等片刻,当看到如图所示的时候,表示缓存更新成功: