nexus 随笔

离线更新中央仓库索引的方式,速度快并且可靠。

  1. 访问http://repo.maven.apache.org/maven2/.index/下载中心仓库最新版本的索引文件,我们需要下载如下两个文件nexus-maven-repository-index.gz和nexus-maven-repository-index.properties。
  2. 进入nexus安装目录\sonatype-work进入indexer目录,因为我们的代理名为central所以找到central-ctx ,将下载好的文件解压进去后。重新启动nexus,若能在central 的browse index中看到和remote一样的索引,即代表成功完成。

settings.xml

<?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>D:\Maven\repository</localRepository>
    <servers>
        <server>
    		<id>public</id>  <!-- 对应server节点的id -->
    		<username>admin</username>
    		<password>admin123</password>
    	</server>
        <server>
            <id>releases</id><!--这个ID要与下面的repository中的ID一致-->
            <username>admin</username>
            <password>admin123</password>
        </server>
        <server>
            <id>snapshots</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
    </servers>
    <mirrors>
        <mirror>
            <id>public</id>  <!-- 对应server节点的id -->
            <name>Public Repositories</name>
            <url>http://xxx/nexus/content/groups/public/</url><!-- 私服仓库地址 -->
            <mirrorOf>*</mirrorOf>
        </mirror>
    </mirrors>

    <profiles>
        <profile>
            <id>public</id>
            <repositories>
                <repository>
                    <id>releases</id><!--正式仓库id-->
                    <name>Releases</name>
                    <url>http://xxx/nexus/content/repositories/releases</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>snapshots</id>
                    <name>Snapshots</name>
                    <url>http://xxx/nexus/content/repositories/snapshots</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories><!--插件仓库地址,各节点的含义和上面是一样的-->
                <pluginRepository>
                    <id>releases</id>
                    <name>Releases</name>
                    <url>http://xxx/nexus/content/repositories/releases</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>snapshots</id>
                    <name>Releases</name>
                    <url>http://xxx/nexus/content/repositories/snapshots</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>public</activeProfile>
    </activeProfiles>
</settings>

pom.xml:

<distributionManagement>
<repository>
    <id>releases</id><!--正式仓库id-->
    <name>Releases</name>
    <url>http://xxx/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
    <id>snapshots</id>
    <name>Snapshots</name>
    <url>http://xxx/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>

一些常用的软件仓库:

  http://maven.aliyun.com/nexus/content/groups/public(阿里云,推荐)
  http://repo1.maven.org/maven2
  http://repository.sonatype.org/content/groups/public/

maven仓库位置寻找

  http://mvnrepository.com

项目中直接使用其他仓库

<repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
posted @ 2019-04-13 14:18  fly_bk  阅读(208)  评论(0编辑  收藏  举报