如何仅使用公司本地nexus存储库

时间:2012-09-04 06:04:03

标签: maven

我想使用nexus创建公司本地maven存储库。存储库不应该从公共互联网下载任何东西,所需的一切都被添加到repo。开发人员的本地maven instanses应该从公司nexus下载所需的库和工具。我已经设法通过在settings.xml中使用这样的镜像来实现这一点:

<mirror>
  <id>company-repository</id>
  <name>Company releases repository</name>
  <url>http://nexus.company.com/nexus/content/repositories/releases</url>
  <mirrorOf>*</mirrorOf>
</mirror>

此解决方案的问题在于我只能指向发布存储库,我想包括第三方和快照存储库以进行搜索。有谁知道应该怎么做?镜像标记只需要一个网址。

我也尝试过这样定义默认配置文件:

<profile>            
    <id>defaultProfile</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <repositories>
        <repository>
            <id>company-thirdparty-repo</id>
            <url>http://nexus.company.com//nexus/content/repositories/thirdparty</url>
            <releases>
                 <checksumPolicy>fail</checksumPolicy> 
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>company-releases-repo</id>
            <url>http://nexus.company.com/nexus/content/repositories/releases</url>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
                <checksumPolicy>fail</checksumPolicy>
            </snapshots>
            <releases>
                <enabled>true</enabled>
                <checksumPolicy>fail</checksumPolicy>
            </releases>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <url>http://nexus.company.com/nexus/content/repositories/central</url>
            <releases>
                <enabled>true</enabled>
                <checksumPolicy>fail</checksumPolicy>
            </releases>
            <snapshots>
                <checksumPolicy>fail</checksumPolicy>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>            
</profile> 

该解决方案的问题在于,如果Maven没有从这些存储库中找到某些内容,它仍然会从repo.maven.apache.org下载它。我将不胜感激任何帮助。谢谢!

1 个答案:

答案 0 :(得分:5)

您可以使用两者的组合:

为远程公共存储库的代理创建存储库组(假设您将其称为公共存储库)。使用它来镜像Maven的唯一默认存储库,即“中心”

对于其他存储库,只需将其添加为存储库/插件存储库

settings.xml如下所示:

<settings>
    <mirrors>
        <mirror>
            <id>nexus</id>
            <mirrorOf>central</mirrorOf>
            <url>http://your/nexus/groups/public</url>
        </mirror>
    </mirrors>

    <profiles>
        <profile>
            <id>nexus</id>
            <repositories>
                <repository>
                    <!-- for you to override settings of central -->
                    <id>central</id>
                    <url>http://a.fake.host</url>
                    <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</enabled></snapshots>
                </repository>
                <repository>
                    <id>anotherRepo</id>
                    <url>http://your/nexus/groups/anotherRepo</url>
                    <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</enabled></snapshots>
                </repository>

            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <!-- for you to override settings of central -->
                    <id>central</id>
                    <url>http://a.fake.host</url>
                    <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</enabled></snapshots>
                </pluginRepository>

                <pluginRepository>
                    <id>anotherRepo</id>
                    <url>http://your/nexus/groups/anotherRepo</url>
                    <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</enabled></snapshots>
                </pluginRepository>
            </pluginRepositories> 
        </profile>
    </profiles>

    <activeProfiles>
        <activeProfile>nexus</activeProfile>
    </activeProfiles>
</settings>