Maven-3.3.9 总是从远程而非本地拉取依赖项

Maven-3.3.9 pulling dependencies always from remote not from Local

我正在从 Maven-3.0.X 迁移到 Maven-3.3.9 以适应最近的 surefire 插件版本。

但是我面临的问题是在这次迁移过程中,我发现 Maven 总是从远程而不是本地提取依赖项,即使我们在本地有可用的存储库。我希望Maven最初会查找本地,如果依赖项不适用然后将拉出远程。

备注

1) 我可以强制我的 maven 进行离线构建 [-o] 或将 -Dmaven.legacyLocalRepo=true 传递给我不想实现的工作。

2) 尝试使用 UpdatePolicy="never" 选项,但没有成功

POM.xml

<?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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com</groupId>
    <artifactId>test</artifactId>
    <version>1.0.0</version>
    <packaging>mule</packaging>
    <name>Test Application</name>

    <build>
        <plugins>
            <plugin>
                <groupId>org.mule.tools.maven</groupId>
                <artifactId>mule-app-maven-plugin</artifactId>
                <version>1.7</version>
                <extensions>true</extensions>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2.1</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>project</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.7</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.4</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.mulesoft.muleesb</groupId>
            <artifactId>mule-core</artifactId>
            <version>3.6.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>Central</id>
            <name>Central</name>
            <url>http://repo1.maven.org/maven2/</url>
            <layout>default</layout>
        </repository>
        <repository>
            <id>mulesoft-releases</id>
            <name>MuleSoft Releases Repository</name>
            <url>http://repository.mulesoft.org/releases/</url>
            <layout>default</layout>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>Central</id>
            <name>Central</name>
            <url>http://repo1.maven.org/maven2/</url>
            <layout>default</layout>
        </pluginRepository>
        <pluginRepository>
            <id>mulesoft-releases</id>
            <name>mulesoft release repository</name>
            <layout>default</layout>
            <url>http://repository.mulesoft.org/releases/</url>
        </pluginRepository>
    </pluginRepositories>
</project>

错误日志

Downloading from repo.nexus: http://127.0.0.1:9080/nexus/content/repositories/public/org/mule/tools/maven/mule-esb-maven-plugins/1.7/mule-esb-maven-plugins-1.7.pom
Downloading from jfrog: http://repo.jfrog.org/artifactory/plugins-releases-local/org/mule/tools/maven/mule-esb-maven-plugins/1.7/mule-esb-maven-plugins-1.7.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Unresolveable build extension: Plugin org.mule.tools.maven:mule-app-maven-plugin:1.7 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.mule.tools.maven:mule-app-maven-plugin:jar:1.7 @ 
[ERROR] Unknown packaging: mule @ line 8, column 16
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.test:TEST_PROJECT:1.0-SNAPSHOT (/usr/local/TEST_PROJECT/pom.xml) has 2 errors
[ERROR]     Unresolveable build extension: Plugin org.mule.tools.maven:mule-app-maven-plugin:1.7 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.mule.tools.maven:mule-app-maven-plugin:jar:1.7: Could not transfer artifact org.mule.tools.maven:mule-esb-maven-plugins:pom:1.7 from/to jfrog (http://repo.jfrog.org/artifactory/plugins-releases-local): Connect to repo.jfrog.org:80 [repo.jfrog.org/52.7.30.14, repo.jfrog.org/34.231.202.145] failed: Connection timed out -> [Help 2]
[ERROR]     Unknown packaging: mule @ line 8, column 16
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/PluginManagerException

我希望 Maven 首先引用本地然后引用远程,因为这是它以前在 Maven-3 中的工作方式。0.X。

我尝试使用 Maven 3.3.9(和 3.6.0)构建您的示例 pom.xml:没有 com.mulesoft.muleesb:mule-core:3.6.0:jar;最接近的似乎是 org.mule:mule-core:3.6.0.

如果没有找到所述依赖项的 POM,Maven 将发出警告并存储一个 .lastUpdated 文件。该文件包含一个时间戳,指示何时为某些存储库发出错误。

在两次执行之间经过一段时间,或者如果使用-U,Maven 将重试下载依赖项(或其 POM)。我认为那是你出错的地方。

POM 对 Maven 不是必需的,它会发出警告:

[WARNING] The POM for com.mulesoft.muleesb:mule-core:jar:3.6.0 is missing, no dependency information available

但是,当它尝试下载它时,它至少必须达到一些 404 NOT FOUND:我使用了一些本地未绑定 IP,但也失败了:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Test Application 1.0.0
[INFO] ------------------------------------------------------------------------
Downloading: https://192.168.113.145/com/mulesoft/muleesb/mule-core/3.6.0/mule-core-3.6.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.336 s
[INFO] Finished at: 2018-12-27T20:04:11+01:00
[INFO] Final Memory: 10M/245M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project test: Could not resolve dependencies for project com:test:mule:1.0.0: Failed to collect dependencies at com.mulesoft.muleesb:mule-core:jar:3.6.0: Failed to read artifact descriptor for com.mulesoft.muleesb:mule-core:jar:3.6.0: Could not transfer artifact com.mulesoft.muleesb:mule-core:pom:3.6.0 from/to bintray (https://192.168.113.145): Connect to 192.168.113.145:443 [/192.168.113.145] failed: Connection timed out: connect -> [Help 1]

这个错误与你的不一样,但至少或多或少解释了为什么 Maven 使用远程。

还有其他情况:

  • 如果 plugin/dependency 没有明确的版本(这意味着 "take the latest",可能在有限的范围内 [例如:maven 的版本,传递依赖。 ..,)。默认插件,如maven-clean-plugin,由Maven版本固定。
  • 您使用 SNAPSHOT 版本,Maven 将获取最新版本(除非在您的 <repository> 中禁用)

话虽如此,我认为你的问题(你的问题)是错误的:

But the problem am facing is during this migration, I found Maven is always pulling the dependencies from remote not from the local even we have the repositories available in the local.

Maven 由于无法远程找到依赖项而失败的事实意味着,在您的配置中,您的构建将无法在另一台机器上运行:

  1. 您的 Nexus 存储库 (http://127.0.0.1:9080/nexus) 没有存储依赖项,这意味着它没有达到目的(拥有企业存储库是为了避免来自外部的问题,首先是删除或替换)。
  2. 它不应该在 127.0.0.1 中,而是在单独的服务器上,除非您出于其他原因将企业存储库代理到您的本地主机;至少,它应该被备份。
  3. 你的 settings.xml 应该使用那个存储库的镜像(如果你想确保你不从外部源下载 dependencies/plugin)。

特别是,如果您更改本地存储库(例如,将 <localRepository> 指向 ~/.m2/repository.fresh),构建应该不会因为缺少依赖项而失败。