mavenmaven-3nexusmaven-centralaws-codeartifact

Is there anyway to force all traffic except Maven Central via Internal Repo?


So, I have a requirement to force all requests to Maven Central via CodeArtifacts, while all other traffic to Nexus repository hosted by organization. My settings.xml looks like below

<mirrors>
 <mirror>
   <id>aws-codeartifact</id>
   <mirrorOf>central</mirrorOf>
   <name>CodeArtifact mirror for Maven Central only</name>
   <url>https://abc-code-artifacts.d.codeartifact.us-east-1.amazonaws.com/maven/maven-test-repo/</url>
 </mirror> 
    
 <mirror>
   <id>abc-nexus</id>
   <mirrorOf>*,!aws-codeartifact</mirrorOf>
   <name>Nexus Group for everything else</name>
   <url>https://nexus.abc.com/repository/repository/maven-group/</url>
</mirror>       

Now the issue, is this doesn't work. It results in all requests to be pulled via my Nexus repo,as if "*" over-rides everything

My requirement is to :

Is this an expected behavior, or is there any work around?


Solution

  • 
    
    <mirrors>
        <mirror>
          <id>internal-repo</id>
          <mirrorOf>*,!central</mirrorOf>
          <url>https://your.internal.repo/repository/mirror/</url>
        </mirror>
      </mirrors>
    
    
    
    
    
      <profiles>
        <profile>
          <id>only-allowed-repos</id>
          <repositories>
            <repository>
              <id>central</id>
              <url>https://repo.maven.apache.org/maven2</url>
            </repository>
          </repositories>
        </profile>
      </profiles>
      <activeProfiles>
        <activeProfile>only-allowed-repos</activeProfile>
      </activeProfiles>
    </settings>