【问题标题】:Maven plugin cannot be resolvedMaven插件无法解析
【发布时间】:2020-08-09 13:08:11
【问题描述】:

我已经按照标题搜索了这个问题,但仍然不知道该怎么办。我正在尝试构建一个可执行的 jar 文件,但其中一个插件 maven-assembly-plugin 无法解析。

我试过https://maven.apache.org/plugins/maven-assembly-plugin/usage.html 但它不起作用。我放了整个pom.xml文件,插件在文件底部。非常感谢任何帮助。

这是错误信息:

Plugin could not be resolved. Ensure the plugin's groupId, artifactId and 
version are present. Additional information: Plugin 
org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5 or one of its 
dependencies could not be resolved: Failed to read 
artifact descriptor for org.apache.maven.plugins:maven-assembly-plugin:jar:2.2-beta-5

这是文件:

<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>distributed.systems</groupId>
<artifactId>leader.election</artifactId>
<version>0.0.1-SNAPSHOT</version>

<name>leader.election</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>

<dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.11</version>
  <scope>test</scope>
</dependency>

<dependency>
  <groupId>org.apache.zookeeper</groupId>
  <artifactId>zookeeper</artifactId>
  <version>3.6.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
  <plugins>
    <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
    <plugin>
      <artifactId>maven-clean-plugin</artifactId>
      <version>3.1.0</version>
    </plugin>
    <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
    <plugin>
      <artifactId>maven-resources-plugin</artifactId>
      <version>3.0.2</version>
    </plugin>
    <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.8.0</version>
    </plugin>
    <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.22.1</version>
    </plugin>
    <plugin>
      <artifactId>maven-jar-plugin</artifactId>
      <version>3.0.2</version>
    </plugin>
    <plugin>
      <artifactId>maven-install-plugin</artifactId>
      <version>2.5.2</version>
    </plugin>
    <plugin>
      <artifactId>maven-deploy-plugin</artifactId>
      <version>2.8.2</version>
    </plugin>
    <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
    <plugin>
      <artifactId>maven-site-plugin</artifactId>
      <version>3.7.1</version>
    </plugin>
    <plugin>
      <artifactId>maven-project-info-reports-plugin</artifactId>
      <version>3.0.0</version>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.8.0</version>
        <configuration>
            <release>14</release>
        </configuration>
    </plugin>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <version>3.3.0</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>single</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <archive>
          <manifest>
            <mainClass>LeaderElection</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
    </plugin> 
  </plugins>
</pluginManagement>

【问题讨论】:

  • 尝试为插件提供groupId(在这种情况下为org.apache.maven.plugins
  • 谢谢,我试试。 @肾脏
  • 有趣的是,它对我来说很好用。你或许可以尝试从~/.m2/repository/org/apache/maven/plugins/maven-assembly-plugin/删除maven-assemply-plugin的本地缓存
  • 除了您的问题:您在编译器插件中声明了&lt;maven.compiler.[source|target]&gt;1.7&lt;release&gt;14。这很矛盾。新的(从 Java 9 开始)&lt;release&gt; 参数替换了旧的两个参数,也可以通过 &lt;properties&gt;/&lt;maven.compiler.release&gt;14 设置,而不是在编译器插件中配置它,并且是 preferred for cross-compiling
  • 谢谢,@GeroldBroser。这是我需要注意的另一部分。

标签: java maven


【解决方案1】:

您可能正在使用旧的 Maven 版本,它试图通过 HTTP 协议获取插件。几个月前该功能已被禁用。您必须使用更新版本的 Maven 或更改本地配置文件 ~/.m2/settings.xml(或 C:\users\you\.m2\settings.xml)以使用 HTTPS。如果没有这样的文件,您可以通过从示例中复制来创建它:

<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
    <profiles>
        <profile>
            <id>stefan</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <repositories>

                <repository>
                    <id>central</id>
                    <url>https://repo1.maven.org/maven2</url>
                    <releases>
                      <updatePolicy>never</updatePolicy>
                    </releases>
                    <snapshots>
                      <enabled>false</enabled>
                    </snapshots>
                </repository>  
 
                <repository>
                    <id>spring-milestones</id>
                    <url>https://repo.springsource.org/libs-milestone/</url>
                    <releases>
                      <updatePolicy>never</updatePolicy>
                    </releases>
                    <snapshots>
                      <enabled>false</enabled>
                    </snapshots>
                </repository>
 
                <repository>
                    <id>jboss</id>
                    <url>https://repository.jboss.org/nexus/content/groups/public/</url>
                    <releases>
                      <updatePolicy>never</updatePolicy>
                    </releases>
                    <snapshots>
                      <enabled>false</enabled>
                    </snapshots>
                </repository>                
            </repositories>    
 
            <pluginRepositories>
                <pluginRepository>
                    <id>central</id>
                    <url>https://repo1.maven.org/maven2</url>
                    <releases>
                      <updatePolicy>never</updatePolicy>
                    </releases>
                    <snapshots>
                      <enabled>false</enabled>
                    </snapshots>
                </pluginRepository> 
            </pluginRepositories>
            
        </profile>
    </profiles>    
</settings>

【讨论】:

  • 谢谢@Stefan,这是我解决这个问题的一个方向。我会试着弄清楚。
  • @Stefan,在 ~/.m2/settings.xml 中有什么变化来通过 HTTPS 协议而不是 HTTP 获取插件?
  • 我在上面添加了一个示例文件。
【解决方案2】:

您必须将 groupId 放在 artifactId 上方。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>       
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.3.0</version>
    <configuration>
        <archive>
            <manifest>
                <mainClass>de.uulm.sp.pvs.sokoban.App</mainClass>
            </manifest>
        </archive>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
    </configuration>
</plugin>

【讨论】:

    【解决方案3】:

    对于这个问题,我决定使用下载的apache maven zip,而不是eclipse内置的maven。

    1. 检查 Maven 是否在 Eclipse 中。 文件 → 新建 → 其他
    2. 安装m2e。 帮助 → 安装新软件 http://download.eclipse.org/technology/m2e/releases
    3. 下载 Maven zip 并将环境变量设置到主文件夹。
    4. 如果成功,在cmd中,mvn --version命令会看到maven的版本及相关信息。
    5. 在下载的maven文件夹中,新建文件夹repository
    6. 在下载的maven文件夹中,找到conf/settings.xml。找到标签&lt;localRepository&gt;,修改刚才创建的repository文件夹的路径。
    7. Windows → 首选项 → Maven → 安装 → 添加 → 下载的 maven 文件夹的目录 → 应用
    8. Maven → 用户设置 → 浏览编辑好的settings.xml → 确定
    9. 重启 Eclipse。

    如果所有进程都成功,则插件问题将得到解决。

    参考:https://o7planning.org/en/10101/install-maven-into-eclipse

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-02
      • 1970-01-01
      • 1970-01-01
      • 2010-12-29
      • 2020-03-24
      • 1970-01-01
      相关资源
      最近更新 更多