简体   繁体   English

Maven 插件无法解决

[英]Maven plugin cannot be resolved

I've searched this problem as the title says but still don't know what I should do.正如标题所说,我已经搜索了这个问题,但仍然不知道我应该做什么。 I am trying to build an executable jar file, but one of the plugins maven-assembly-plugin cannot be resolved.我正在尝试构建一个可执行的 jar 文件,但其中一个插件maven-assembly-plugin无法解析。

I've tried the https://maven.apache.org/plugins/maven-assembly-plugin/usage.html but it doesn't work.我试过https://maven.apache.org/plugins/maven-assembly-plugin/usage.html但它不起作用。 I put the entire pom.xml file, and the plugin is at the bottom of the file.我放了整个pom.xml文件,插件在文件底部。 Any help is highly appreciated.非常感谢任何帮助。

Here is the error message:这是错误消息:

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

Here is the file:这是文件:

<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>

You are possibly using an old Maven version that tries to fetch plugins via HTTP protocol.您可能正在使用旧的 Maven 版本,它试图通过 HTTP 协议获取插件。 That has been disabled a few month ago.几个月前该功能已被禁用。 You must either use a more recent version of Maven or change your local configuration file ~/.m2/settings.xml (or C:\users\you\.m2\settings.xml ) to use HTTPS. You must either use a more recent version of Maven or change your local configuration file ~/.m2/settings.xml (or C:\users\you\.m2\settings.xml ) to use HTTPS. If there is no such file, you can create it by copying from the example:如果没有这样的文件,您可以通过从示例中复制来创建它:

<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>

You have to put the groupId in above the artifactId.您必须将 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>

For this question, I decided to use the downloaded apache maven zip instead of the built-in maven in eclipse. For this question, I decided to use the downloaded apache maven zip instead of the built-in maven in eclipse.

  1. Check if Maven inside eclipse.检查 Maven 是否在 eclipse 内。 File → New → Other文件 → 新建 → 其他
  2. Install m2e .安装m2e Help → Install New Software http://download.eclipse.org/technology/m2e/releases帮助 → 安装新软件http://download.eclipse.org/technology/m2e/releases
  3. Download the Maven zip and set the environment variables to the main folder.下载 Maven zip 并将环境变量设置为主文件夹。
  4. If successful, in cmd, mvn --version command shall see the version of maven and related information.如果成功,在 cmd 中, mvn --version命令会看到 maven 的版本和相关信息。
  5. In the downloaded maven folder, create a new folder repository .在下载的 maven 文件夹中,新建文件夹repository
  6. In the downloaded maven folder, find conf/settings.xml .在下载的 maven 文件夹中,找到conf/settings.xml Find the tag <localRepository> and modify the path to the repository folder just created.找到标签<localRepository>并修改刚刚创建的repository文件夹的路径。
  7. Windows → Preferences → Maven → Installations → Add → Directory to the downloaded maven folder → Apply Windows → 首选项 → Maven → 安装 → 添加 → 目录到下载的 maven 文件夹 → 应用
  8. Maven → User Settings → Browse the edited settings.xml → OK Maven → 用户设置 → 浏览已编辑的settings.xml 。xml → 确定
  9. Restart eclipse.重启 eclipse。

If all processes are successful, then the plugin issue will be resolved.如果所有过程都成功,则插件问题将得到解决。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM