Maven-3.3.9总是从远程而不是从本地拉依赖关系

时间:2018-12-24 11:51:20

标签: maven maven-3 maven-plugin

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

但是面临的问题是在迁移过程中,我发现Maven总是从远程而不是从本地拉依赖性,即使我们在本地有可用的存储库。我希望Maven最初会查找本地,如果依赖项NA那么会拉出远程服务器。

注意

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以前的工作方式。

1 个答案:

答案 0 :(得分:1)

我试图使用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)。我认为那是您出错的地方。

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

[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选择远程。

还有其他情况:

  • 如果插件/依赖项没有显式版本,Maven将尝试从存储库下载插件元数据(这意味着“采用最新版本”,可能范围有限[例如:maven的版本,可传递的依赖项...,) 。默认插件,例如maven-clean-plugin,由Maven的版本修复。
  • 您使用SNAPSHOT版本,Maven将获取最新版本(除非您的<repository>中已禁用)

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

  

但是面临的问题是在迁移期间,我发现Maven是   总是从远程而不是本地拉依赖性   在本地有可用的存储库。

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

  1. 您的Nexus存储库(http://127.0.0.1:9080/nexus)没有存储依赖关系,这意味着它没有达到目的(企业存储库是从外部解决问题,首先是移除或替换问题)。
  2. 它不应位于127.0.0.1中,而应位于单独的服务器上,除非您出于其他原因将企业存储库代理到本地主机;至少应该备份。
  3. 您的settings.xml应该使用该存储库的镜像(如果要确保您不从外部源下载依赖项/插件)。

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