12
votes

I would like to create company local maven repository using nexus. Repository should not download anything from public internet, everything needed is added to repo. Developer's local maven instanses should download needed libraries and tools from company nexus. I have managed to do this by using mirror like this in 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>

Problem with this solution is that I am only able to point to releases repository, I would like to include thirdparty and snapshot repository to search as well. Has anyone any idea how that should be done? Mirror tag takes only one url.

I also tried with defining default profile like this:

<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> 

Problem with that solution is that if Maven don't find something from those repositories it still downloads it from repo.maven.apache.org. I will appreciate any help. Thanks!

1

1 Answers

5
votes

You can use combination of both:

Create a repository group for the proxies of remote public repo (assume you call it public). Use this to mirror the only default repository of Maven, which is "central"

For other repositories, just add it as repository/plugin repo

the settings.xml looks like this:

<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>