3

我有一个 pom,我将不同的 repo 定义为中心(在存储库和 pluginRepositorie 中),但是,当我运行 mvn install 时,我在 maven 转到的日志中看到:https://repo.maven.apache.org

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

日志:

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   

当我查看我的工件(jfrog)时,我看到元数据和有时更多的文件(如 source.jar)被定义为“未缓存”。也许它与问题有关?

另外,当我使用Mirrors时,maven没有去maven-central,但是编译成功了。

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

4

2 回答 2

2

即使您没有将中央存储库添加到您的项目中,您的项目也会从超级 pom.xml 继承中央存储库。您可以通过镜像完全排除中央存储库,您可以在此处阅读更多内容。

默认情况下,maven 首先检查本地存储库,然后检查 setting.xml 中添加的存储库。

我在你的日志中看到的也意味着 maven 正在下载一些我认为用于运行程序集插件的核心依赖项,我猜你没有这些基本依赖项,并且因为 maven 从中央仓库获取它们。

于 2020-03-04T08:57:35.223 回答
0

这里的问题在于 id 标签“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>

这是链接,(在这里搜索单词“central”)。有一次它说“中央”指向 Maven 中央存储库。( https://repo.maven.apache.org/maven2/ ))

因此,如果它指向某个自定义存储库,则解决方案是不要在您的 id 中使用“中心”字。例如-您的关系存储库等。

于 2021-03-16T05:14:08.773 回答