Maven 去 https ://repo. maven.apache.org/maven2/在编译阶段,即使不同的 repo 被定义为 "central"

标签 maven pom.xml maven-assembly-plugin mirror jfrog-mission-control

我有一个 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>

最佳答案

即使你没有将中央仓库添加到你的项目中,你的项目也会从 super pom 中继承中央仓库。您可以通过镜像完全排除中央存储库,您可以阅读更多here .

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

此外,我在您的日志中看到的内容暗示 maven 正在下载一些我认为用于运行程序集插件的核心依赖项,我猜您没有这些基本依赖项,因为 maven 从中央 Repo 获取它们。

关于Maven 去 https ://repo. maven.apache.org/maven2/在编译阶段,即使不同的 repo 被定义为 "central",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60520443/

相关文章:

maven-2 - 未构建 Maven 子模块

maven - Artifactory 中的依赖解析配置

java - Maven maven-assembly-plugin 使用配置文件构建

Maven:是否可以创建仅包含依赖项的胖 jar 和仅包含应用程序代码的 jar?

java - 我的 Maven 项目 VSCode 没有主要 list 属性错误

java - 无法使用maven插件在tomcat中启动Spring应用程序

Java 9 - 我可以将 MainClass 属性添加到存档中的 module-info.class 吗?

java - 让 Maven 执行程序并将输出存储到可在 .jar list 中使用的属性中

maven - 使用公司范围的 super /父 POM 覆盖 super POM

maven - maven 程序集插件可以选择指定的 java 包吗?