无法读取 org.apache.maven.plugins:maven-source-plugin:jar:2.4 的工件描述符

Failed to read artifact descriptor for org.apache.maven.plugins:maven-source-plugin:jar:2.4

感谢 Dropwizard Maven 原型,我生成了一个示例 Dropwizard Maven 项目。 pom.xml 特别使用了 maven-source-plugin:

<plugin>
    <artifactId>maven-source-plugin</artifactId>
    <version>2.4</version>
    <executions>
        <execution>
           <id>attach-sources</id>
           <goals>
              <goal>jar</goal>
           </goals>
        </execution>
    </executions>
</plugin>

当我 运行 "clean install" 我有以下错误:

Plugin org.apache.maven.plugins:maven-source-plugin:2.4 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-source-plugin:jar:2.4: Could not transfer artifact org.apache.maven.plugins:maven-source-plugin:pom:2.4 from/to central (http://repo.maven.apache.org/maven2): Connection refused: connect -> [Help 1]

"maven-source-plugin" 依赖存储在我公司的 Nexus 存储库中。所以我尝试在 dependencies 和 /dependencies 之间添加插件依赖:

<dependencies>
    ...
    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>2.4</version>
    </dependency>
</dependencies>

但它并没有解决问题。我还尝试在插件调用时添加依赖项:

 <plugin>
    <artifactId>maven-source-plugin</artifactId>
    <version>2.4</version>
    <executions>
       <execution>
           <id>attach-sources</id>
           <goals>
              <goal>jar</goal>
           </goals>
       </execution>
      </executions>
      <dependencies>
          <dependency>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-source-plugin</artifactId>
              <version>2.4</version>
          </dependency>
     </dependencies>
 </plugin>

但是也没用

org.apache.maven.plugins:maven-source-plugin 不存在于存储库 http://repo.maven.apache.org/maven2 中。

你必须从它存在的 Maven 中心下载它 => maven-source-plugin

验证您的 pom 定义或您的 settings.xml 文件。

两种可能的情况:

  • 您的公司使用代理连接到 public Maven 存储库。然后问问你们公司的人代理的 IP 地址是什么然后把它放在你们的 settings.xml 文件

  • 您的公司有 its/their 自己的 Maven repository/ies(例如 Nexus 存储库)。然后询问您公司的某个人 Nexus 存储库是什么,然后将其放入您的 pom.xml 或 settings.xml 中。参见 Adding maven nexus repo to my pom.xml and https://maven.apache.org/guides/mini/guide-multiple-repositories.html

更新 apache-maven-3.5.0-bin\apache-maven-3.5.0\conf\settings.xml 文件。

检查您的 Internet Explorer 代理 --> 设置 --> Internet Explorer --> 连接 --> LAN 设置

<proxy>
  <id>optional</id>
  <active>true</active>
  <protocol>http</protocol>
  <username>user</username>
  <password>****</password>
  <host>proxy</host>
  <port>8080</port>
</proxy>

所以我假设你在你的私人日食中做这个项目(不是公司提供的你工作的日食)。我解决的问题如下

快速修复:获取 .m2 文件 --> 创建 settings.xml 的备份 --> 删除 settings.xml --> 重新启动您的 eclipse。

I use intelliJ and finally I created my own settings.xml and added the following content structure to it. In my project's pom.xml, the nexus repositories were defined but for some reason it was always hitting the external apache maven repo which is blocked in my company.

<settings>
  <mirrors>
     <id>nexus</id>
     <url>nexusURL </url>
     <mirrorOf>central</mirrorOf>
    <mirror>

<profiles>
  <profile>
    <repositories>
      <repository>

</settings>

这可能会发生,例如下载中断后,Maven 在您的本地存储库中缓存了引用包的损坏版本

解决方法:手动从缓存中删除此插件的文件夹(即您的本地存储库),然后重复maven install

如何找到正确的文件夹? Maven 存储库中的文件夹遵循以下结构:

<dependency>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>2.4</version>
</dependency>

缓存在${USER_HOME}\.m2\repository\org\apache\maven\plugins\maven-source-plugin.4

在我这边,它来自我的 settings.xml 文件中的错误。 我有一个坏标签。刚刚删除它,精神焕发,我很高兴。

我在 Maven 项目中使用 JDK 7,我在 JRE 中使用 -Dhttps.protocols=TLSv1.2 作为参数。它允许下载之前失败的所有 Maven 存储库。

删除文件夹 \.m2\repository\org\apache\maven\plugins\maven-resource-plugin.7 的内容。缓存的信息原来是问题所在。