Maven插件无法解析

huangapple go评论83阅读模式
英文:

Maven plugin cannot be resolved

问题

我搜索了这个问题,如标题所示,但仍然不知道我应该做什么。我正在尝试构建一个可执行的JAR文件,但其中一个插件maven-assembly-plugin无法解析。

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

以下是错误消息:

插件无法解析。确保插件的groupId、artifactId和version都存在。附加信息:插件org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5或其依赖项之一无法解析:无法读取org.apache.maven.plugins:maven-assembly-plugin:jar:2.2-beta-5的构件描述符

以下是文件:

<?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/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>
</build>
</project>

注意:以上是您提供的XML代码的翻译。

英文:

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.

I've tried the https://maven.apache.org/plugins/maven-assembly-plugin/usage.html
but it doesn't work. I put the entire pom.xml file, and the plugin is at the bottom of the file. Any help is highly appreciated.

Here is the error message:

Plugin could not be resolved. Ensure the plugin&#39;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:
<?xml version="1.0" encoding="UTF-8"?>

&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema- instance&quot;
xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;groupId&gt;distributed.systems&lt;/groupId&gt;
&lt;artifactId&gt;leader.election&lt;/artifactId&gt;
&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
&lt;name&gt;leader.election&lt;/name&gt;
&lt;!-- FIXME change it to the project&#39;s website --&gt;
&lt;url&gt;http://www.example.com&lt;/url&gt;
&lt;properties&gt;
&lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
&lt;maven.compiler.source&gt;1.7&lt;/maven.compiler.source&gt;
&lt;maven.compiler.target&gt;1.7&lt;/maven.compiler.target&gt;
&lt;/properties&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;junit&lt;/groupId&gt;
&lt;artifactId&gt;junit&lt;/artifactId&gt;
&lt;version&gt;4.11&lt;/version&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.zookeeper&lt;/groupId&gt;
&lt;artifactId&gt;zookeeper&lt;/artifactId&gt;
&lt;version&gt;3.6.1&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;pluginManagement&gt;&lt;!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --&gt;
&lt;plugins&gt;
&lt;!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-clean-plugin&lt;/artifactId&gt;
&lt;version&gt;3.1.0&lt;/version&gt;
&lt;/plugin&gt;
&lt;!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
&lt;version&gt;3.0.2&lt;/version&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&lt;version&gt;3.8.0&lt;/version&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
&lt;version&gt;2.22.1&lt;/version&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
&lt;version&gt;3.0.2&lt;/version&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-install-plugin&lt;/artifactId&gt;
&lt;version&gt;2.5.2&lt;/version&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-deploy-plugin&lt;/artifactId&gt;
&lt;version&gt;2.8.2&lt;/version&gt;
&lt;/plugin&gt;
&lt;!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-site-plugin&lt;/artifactId&gt;
&lt;version&gt;3.7.1&lt;/version&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-project-info-reports-plugin&lt;/artifactId&gt;
&lt;version&gt;3.0.0&lt;/version&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&lt;version&gt;3.8.0&lt;/version&gt;
&lt;configuration&gt;
&lt;release&gt;14&lt;/release&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
&lt;version&gt;3.3.0&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;phase&gt;package&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;single&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;configuration&gt;
&lt;archive&gt;
&lt;manifest&gt;
&lt;mainClass&gt;LeaderElection&lt;/mainClass&gt;
&lt;/manifest&gt;
&lt;/archive&gt;
&lt;descriptorRefs&gt;
&lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
&lt;/descriptorRefs&gt;
&lt;/configuration&gt;
&lt;/plugin&gt; 
&lt;/plugins&gt;
&lt;/pluginManagement&gt;

</build>
</project>

答案1

得分: 5

您可能正在使用一个旧版本的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>
英文:

You are possibly using an old Maven version that tries to fetch plugins via HTTP protocol. 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. If there is no such file, you can create it by copying from the example:

&lt;settings xmlns=&quot;http://maven.apache.org/SETTINGS/1.1.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd&quot;&gt;
&lt;profiles&gt;
&lt;profile&gt;
&lt;id&gt;stefan&lt;/id&gt;
&lt;activation&gt;
&lt;activeByDefault&gt;true&lt;/activeByDefault&gt;
&lt;/activation&gt;
&lt;repositories&gt;
&lt;repository&gt;
&lt;id&gt;central&lt;/id&gt;
&lt;url&gt;https://repo1.maven.org/maven2&lt;/url&gt;
&lt;releases&gt;
&lt;updatePolicy&gt;never&lt;/updatePolicy&gt;
&lt;/releases&gt;
&lt;snapshots&gt;
&lt;enabled&gt;false&lt;/enabled&gt;
&lt;/snapshots&gt;
&lt;/repository&gt;  
&lt;repository&gt;
&lt;id&gt;spring-milestones&lt;/id&gt;
&lt;url&gt;https://repo.springsource.org/libs-milestone/&lt;/url&gt;
&lt;releases&gt;
&lt;updatePolicy&gt;never&lt;/updatePolicy&gt;
&lt;/releases&gt;
&lt;snapshots&gt;
&lt;enabled&gt;false&lt;/enabled&gt;
&lt;/snapshots&gt;
&lt;/repository&gt;
&lt;repository&gt;
&lt;id&gt;jboss&lt;/id&gt;
&lt;url&gt;https://repository.jboss.org/nexus/content/groups/public/&lt;/url&gt;
&lt;releases&gt;
&lt;updatePolicy&gt;never&lt;/updatePolicy&gt;
&lt;/releases&gt;
&lt;snapshots&gt;
&lt;enabled&gt;false&lt;/enabled&gt;
&lt;/snapshots&gt;
&lt;/repository&gt;                
&lt;/repositories&gt;    
&lt;pluginRepositories&gt;
&lt;pluginRepository&gt;
&lt;id&gt;central&lt;/id&gt;
&lt;url&gt;https://repo1.maven.org/maven2&lt;/url&gt;
&lt;releases&gt;
&lt;updatePolicy&gt;never&lt;/updatePolicy&gt;
&lt;/releases&gt;
&lt;snapshots&gt;
&lt;enabled&gt;false&lt;/enabled&gt;
&lt;/snapshots&gt;
&lt;/pluginRepository&gt; 
&lt;/pluginRepositories&gt;
&lt;/profile&gt;
&lt;/profiles&gt;    
&lt;/settings&gt;

答案2

得分: 3

你必须将groupId放在artifactId之上。

&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;		  
&lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
&lt;version&gt;3.3.0&lt;/version&gt;
&lt;configuration&gt;
&lt;archive&gt;
&lt;manifest&gt;
&lt;mainClass&gt;de.uulm.sp.pvs.sokoban.App&lt;/mainClass&gt;
&lt;/manifest&gt;
&lt;/archive&gt;
&lt;descriptorRefs&gt;
&lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
&lt;/descriptorRefs&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
英文:

You have to put the groupId in above the artifactId.

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

答案3

得分: 0

对于这个问题,我决定使用下载的Apache Maven压缩包而不是Eclipse内置的Maven。

  1. 检查Eclipse内是否已安装Maven。
    文件 → 新建 → 其他

  2. 安装m2e插件。
    帮助 → 安装新软件 http://download.eclipse.org/technology/m2e/releases

  3. 下载Maven压缩包并设置环境变量到主文件夹。

  4. 如果成功,在命令提示符中执行 mvn --version 命令将会看到Maven的版本和相关信息。

  5. 在已下载的Maven文件夹中,创建一个新文件夹 repository

  6. 在已下载的Maven文件夹中,找到 conf/settings.xml。查找标签 <localRepository> 并修改路径为刚刚创建的 repository 文件夹。

  7. Windows → 首选项 → Maven → 安装 → 添加 → 选择已下载的Maven文件夹 → 应用

  8. Maven → 用户设置 → 浏览编辑过的 settings.xml → 确定

  9. 重启Eclipse。

如果所有步骤都成功完成,插件问题将会解决。

参考链接:https://o7planning.org/en/10101/install-maven-into-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.
    File → New → Other
  2. Install m2e.
    Help → Install New Software http://download.eclipse.org/technology/m2e/releases
  3. Download the Maven zip and set the environment variables to the main folder.
  4. If successful, in cmd, mvn --version command shall see the version of maven and related information.
  5. In the downloaded maven folder, create a new folder repository.
  6. In the downloaded maven folder, find conf/settings.xml. Find the tag &lt;localRepository&gt; and modify the path to the repository folder just created.
  7. Windows → Preferences → Maven → Installations → Add → Directory to the downloaded maven folder → Apply
  8. Maven → User Settings → Browse the edited settings.xml → OK
  9. Restart eclipse.

If all processes are successful, then the plugin issue will be resolved.

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

huangapple
  • 本文由 发表于 2020年8月9日 21:08:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/63326709.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定