3

I have a pom that I defined different repo as central (in both repositories and pluginRepositorie) and yet, when I run mvn install I see in the log that maven goes to: https://repo.maven.apache.org .

my pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>Test</artifactId>
    <version>1.0-SNAPSHOT</version>

    <repositories>
        <repository>
            <id>central</id>
            <name>My-repo</name>
            <url>http://My-repo/remote</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <name>My-repo-release</name>
            <url>http://my-repo/plugins-release</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>

        <pluginRepository>
            <id>release</id>
            <name>My-repo-snapshot</name>
            <url>http://my-repo/plugins-snapshot</url>
            <releases>
                <enabled>false</enabled>
            </releases>
        </pluginRepository>

    </pluginRepositories>

    <dependencies>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>22.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.1</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <finalName>${project.artifactId}</finalName>
                    <appendAssemblyId>false</appendAssemblyId>
                    <outputDirectory>${project.parent.basedir}/plugins</outputDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

The log:

Downloaded from central: http://my-repo/plugins-release/commons-codec/commons-codec/1.6/commons-codec-1.6.jar (233 kB at 226 kB/s)
Downloaded from central: http://my-repo/plugins-release/org/codehaus/plexus/plexus-utils/3.1.0/plexus-utils-3.1.0.jar (262 kB at 253 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/felix/maven-bundle-plugin/2.5.0/maven-bundle-plugin-2.5.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/felix/maven-bundle-plugin/2.5.0/maven-bundle-plugin-2.5.0.pom (0 B at 0 B/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/felix/felix-parent/2.1/felix-parent-2.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/felix/felix-parent/2.1/felix-parent-2.1.pom (0 B at 0 B/s)
Downloading from central: https://repo.maven.apache.org/maven2/biz/aQute/bnd/bndlib/2.3.0/bndlib-2.3.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/biz/aQute/bnd/bndlib/2.3.0/bndlib-2.3.0.pom (0 B at 0 B/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/osgi/org.osgi.core/4.3.1/org.osgi.core-4.3.1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/osgi/org.osgi.core/4.3.1/org.osgi.core-4.3.1.pom (0 B at 0 B/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/felix/org.apache.felix.bundlerepository/1.6.6/org.apache.felix.bundlerepository-1.6.6.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/felix/org.apache.felix.bundlerepository/1.6.6/org.apache.felix.bundlerepository-1.6.6.pom (0 B at 0 B/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/osgi/org.osgi.core/4.1.0/org.osgi.core-4.1.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/osgi/org.osgi.core/4.1.0/org.osgi.core-4.1.0.pom (0 B at 0 B/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/easymock/easymock/2.4/easymock-2.4.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/easymock/easymock/2.4/easymock-2.4.pom (0 B at 0 B/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/felix/org.apache.felix.utils/1.6.0/org.apache.felix.utils-1.6.0.pom
Progress (1): 2.2/3.3 kB
Progress (1): 3.3 kB   

When I looked at my artifactory (jfrog) I saw that the metadata and sometimes more files (like source.jar) are define as "not cached". Maybe it relate to the issue?

Also, when I use Mirrors, maven didn't goes to maven-central, but the compilation is pass successfully.

The mirrors in my setting.xml:

<mirrors>
    <mirror>
      <id>internal-repository</id>
      <name>Maven Repository Manager running on repo.mycompany.com</name>
      <url>http://My-repo/remote</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>

yiaca
  • 147
  • 2
  • 17

2 Answers2

2

Even though you have not added the central repository to your project, your project inherits the central repository from super pom. you can totally exclude central repository by mirroring, you can read more here.

maven by defaults first checks local repository and then checks added repositories in setting.xml.

also what I can see in your log implies that maven is downloading some core dependencies which I think is used to run assembly plugin, i guess you do not have these base dependencies and because of that maven getting them from central Repo.

frdsprtrdr
  • 384
  • 1
  • 2
  • 11
  • So, even though I defined different repo as central, if there is a missing dependency maven will go to maven-central? Because it doesn't happen all the time, when I add a new dependency (or new version) that I doesn't have in my artifactory, the completion fails (and it doesn't go to maven-central). Also, when I used mirror, the complication passed successfully without going to maven-central. Meaning I does have these artifacts in my artifactory, so why going to maven-central? – yiaca Mar 04 '20 at 10:07
0

Here the issue is with the name given in id tag "central".

<repositories>
        <repository>
            <id>maven-central</id>
            <name>My-repo</name>
            <url>http://My-repo/remote</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>maven-central</id>
            <name>My-repo-release</name>
            <url>http://my-repo/plugins-release</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>

        <pluginRepository>
            <id>release</id>
            <name>My-repo-snapshot</name>
            <url>http://my-repo/plugins-snapshot</url>
            <releases>
                <enabled>false</enabled>
            </releases>
        </pluginRepository>

    </pluginRepositories>

Here is the link, (search here word "central"). At one point it says that "central" is pointing to maven central repository. (https://repo.maven.apache.org/maven2/))

So the solution is not to use "central" word in your id if it is point to some custom repository. E.g.- your nexus repository or etc.

Atul
  • 3,043
  • 27
  • 39