Maven插件无法解析

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

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的构件描述符

以下是文件:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <groupId>distributed.systems</groupId>
  6. <artifactId>leader.election</artifactId>
  7. <version>0.0.1-SNAPSHOT</version>
  8. <name>leader.election</name>
  9. <!-- FIXME change it to the project's website -->
  10. <url>http://www.example.com</url>
  11. <properties>
  12. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  13. <maven.compiler.source>1.7</maven.compiler.source>
  14. <maven.compiler.target>1.7</maven.compiler.target>
  15. </properties>
  16. <dependencies>
  17. <dependency>
  18. <groupId>junit</groupId>
  19. <artifactId>junit</artifactId>
  20. <version>4.11</version>
  21. <scope>test</scope>
  22. </dependency>
  23. <dependency>
  24. <groupId>org.apache.zookeeper</groupId>
  25. <artifactId>zookeeper</artifactId>
  26. <version>3.6.1</version>
  27. </dependency>
  28. </dependencies>
  29. <build>
  30. <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
  31. <plugins>
  32. <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
  33. <plugin>
  34. <artifactId>maven-clean-plugin</artifactId>
  35. <version>3.1.0</version>
  36. </plugin>
  37. <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
  38. <plugin>
  39. <artifactId>maven-resources-plugin</artifactId>
  40. <version>3.0.2</version>
  41. </plugin>
  42. <plugin>
  43. <artifactId>maven-compiler-plugin</artifactId>
  44. <version>3.8.0</version>
  45. </plugin>
  46. <plugin>
  47. <artifactId>maven-surefire-plugin</artifactId>
  48. <version>2.22.1</version>
  49. </plugin>
  50. <plugin>
  51. <artifactId>maven-jar-plugin</artifactId>
  52. <version>3.0.2</version>
  53. </plugin>
  54. <plugin>
  55. <artifactId>maven-install-plugin</artifactId>
  56. <version>2.5.2</version>
  57. </plugin>
  58. <plugin>
  59. <artifactId>maven-deploy-plugin</artifactId>
  60. <version>2.8.2</version>
  61. </plugin>
  62. <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
  63. <plugin>
  64. <artifactId>maven-site-plugin</artifactId>
  65. <version>3.7.1</version>
  66. </plugin>
  67. <plugin>
  68. <artifactId>maven-project-info-reports-plugin</artifactId>
  69. <version>3.0.0</version>
  70. </plugin>
  71. <plugin>
  72. <groupId>org.apache.maven.plugins</groupId>
  73. <artifactId>maven-compiler-plugin</artifactId>
  74. <version>3.8.0</version>
  75. <configuration>
  76. <release>14</release>
  77. </configuration>
  78. </plugin>
  79. <plugin>
  80. <artifactId>maven-assembly-plugin</artifactId>
  81. <version>3.3.0</version>
  82. <executions>
  83. <execution>
  84. <phase>package</phase>
  85. <goals>
  86. <goal>single</goal>
  87. </goals>
  88. </execution>
  89. </executions>
  90. <configuration>
  91. <archive>
  92. <manifest>
  93. <mainClass>LeaderElection</mainClass>
  94. </manifest>
  95. </archive>
  96. <descriptorRefs>
  97. <descriptorRef>jar-with-dependencies</descriptorRef>
  98. </descriptorRefs>
  99. </configuration>
  100. </plugin>
  101. </plugins>
  102. </pluginManagement>
  103. </build>
  104. </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:

  1. Plugin could not be resolved. Ensure the plugin&#39;s groupId, artifactId and
  2. version are present. Additional information: Plugin
  3. org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5 or one of its
  4. dependencies could not be resolved: Failed to read
  5. 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"?>

  1. &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema- instance&quot;
  2. xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  3. &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  4. &lt;groupId&gt;distributed.systems&lt;/groupId&gt;
  5. &lt;artifactId&gt;leader.election&lt;/artifactId&gt;
  6. &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  7. &lt;name&gt;leader.election&lt;/name&gt;
  8. &lt;!-- FIXME change it to the project&#39;s website --&gt;
  9. &lt;url&gt;http://www.example.com&lt;/url&gt;
  10. &lt;properties&gt;
  11. &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
  12. &lt;maven.compiler.source&gt;1.7&lt;/maven.compiler.source&gt;
  13. &lt;maven.compiler.target&gt;1.7&lt;/maven.compiler.target&gt;
  14. &lt;/properties&gt;
  15. &lt;dependencies&gt;
  16. &lt;dependency&gt;
  17. &lt;groupId&gt;junit&lt;/groupId&gt;
  18. &lt;artifactId&gt;junit&lt;/artifactId&gt;
  19. &lt;version&gt;4.11&lt;/version&gt;
  20. &lt;scope&gt;test&lt;/scope&gt;
  21. &lt;/dependency&gt;
  22. &lt;dependency&gt;
  23. &lt;groupId&gt;org.apache.zookeeper&lt;/groupId&gt;
  24. &lt;artifactId&gt;zookeeper&lt;/artifactId&gt;
  25. &lt;version&gt;3.6.1&lt;/version&gt;
  26. &lt;/dependency&gt;
  27. &lt;/dependencies&gt;
  28. &lt;build&gt;
  29. &lt;pluginManagement&gt;&lt;!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --&gt;
  30. &lt;plugins&gt;
  31. &lt;!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --&gt;
  32. &lt;plugin&gt;
  33. &lt;artifactId&gt;maven-clean-plugin&lt;/artifactId&gt;
  34. &lt;version&gt;3.1.0&lt;/version&gt;
  35. &lt;/plugin&gt;
  36. &lt;!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --&gt;
  37. &lt;plugin&gt;
  38. &lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
  39. &lt;version&gt;3.0.2&lt;/version&gt;
  40. &lt;/plugin&gt;
  41. &lt;plugin&gt;
  42. &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
  43. &lt;version&gt;3.8.0&lt;/version&gt;
  44. &lt;/plugin&gt;
  45. &lt;plugin&gt;
  46. &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
  47. &lt;version&gt;2.22.1&lt;/version&gt;
  48. &lt;/plugin&gt;
  49. &lt;plugin&gt;
  50. &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
  51. &lt;version&gt;3.0.2&lt;/version&gt;
  52. &lt;/plugin&gt;
  53. &lt;plugin&gt;
  54. &lt;artifactId&gt;maven-install-plugin&lt;/artifactId&gt;
  55. &lt;version&gt;2.5.2&lt;/version&gt;
  56. &lt;/plugin&gt;
  57. &lt;plugin&gt;
  58. &lt;artifactId&gt;maven-deploy-plugin&lt;/artifactId&gt;
  59. &lt;version&gt;2.8.2&lt;/version&gt;
  60. &lt;/plugin&gt;
  61. &lt;!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --&gt;
  62. &lt;plugin&gt;
  63. &lt;artifactId&gt;maven-site-plugin&lt;/artifactId&gt;
  64. &lt;version&gt;3.7.1&lt;/version&gt;
  65. &lt;/plugin&gt;
  66. &lt;plugin&gt;
  67. &lt;artifactId&gt;maven-project-info-reports-plugin&lt;/artifactId&gt;
  68. &lt;version&gt;3.0.0&lt;/version&gt;
  69. &lt;/plugin&gt;
  70. &lt;plugin&gt;
  71. &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  72. &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
  73. &lt;version&gt;3.8.0&lt;/version&gt;
  74. &lt;configuration&gt;
  75. &lt;release&gt;14&lt;/release&gt;
  76. &lt;/configuration&gt;
  77. &lt;/plugin&gt;
  78. &lt;plugin&gt;
  79. &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
  80. &lt;version&gt;3.3.0&lt;/version&gt;
  81. &lt;executions&gt;
  82. &lt;execution&gt;
  83. &lt;phase&gt;package&lt;/phase&gt;
  84. &lt;goals&gt;
  85. &lt;goal&gt;single&lt;/goal&gt;
  86. &lt;/goals&gt;
  87. &lt;/execution&gt;
  88. &lt;/executions&gt;
  89. &lt;configuration&gt;
  90. &lt;archive&gt;
  91. &lt;manifest&gt;
  92. &lt;mainClass&gt;LeaderElection&lt;/mainClass&gt;
  93. &lt;/manifest&gt;
  94. &lt;/archive&gt;
  95. &lt;descriptorRefs&gt;
  96. &lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
  97. &lt;/descriptorRefs&gt;
  98. &lt;/configuration&gt;
  99. &lt;/plugin&gt;
  100. &lt;/plugins&gt;
  101. &lt;/pluginManagement&gt;

</build>
</project>

答案1

得分: 5

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

  1. <settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
  3. <profiles>
  4. <profile>
  5. <id>stefan</id>
  6. <activation>
  7. <activeByDefault>true</activeByDefault>
  8. </activation>
  9. <repositories>
  10. <repository>
  11. <id>central</id>
  12. <url>https://repo1.maven.org/maven2</url>
  13. <releases>
  14. <updatePolicy>never</updatePolicy>
  15. </releases>
  16. <snapshots>
  17. <enabled>false</enabled>
  18. </snapshots>
  19. </repository>
  20. <repository>
  21. <id>spring-milestones</id>
  22. <url>https://repo.springsource.org/libs-milestone/</url>
  23. <releases>
  24. <updatePolicy>never</updatePolicy>
  25. </releases>
  26. <snapshots>
  27. <enabled>false</enabled>
  28. </snapshots>
  29. </repository>
  30. <repository>
  31. <id>jboss</id>
  32. <url>https://repository.jboss.org/nexus/content/groups/public/</url>
  33. <releases>
  34. <updatePolicy>never</updatePolicy>
  35. </releases>
  36. <snapshots>
  37. <enabled>false</enabled>
  38. </snapshots>
  39. </repository>
  40. </repositories>
  41. <pluginRepositories>
  42. <pluginRepository>
  43. <id>central</id>
  44. <url>https://repo1.maven.org/maven2</url>
  45. <releases>
  46. <updatePolicy>never</updatePolicy>
  47. </releases>
  48. <snapshots>
  49. <enabled>false</enabled>
  50. </snapshots>
  51. </pluginRepository>
  52. </pluginRepositories>
  53. </profile>
  54. </profiles>
  55. </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:

  1. &lt;settings xmlns=&quot;http://maven.apache.org/SETTINGS/1.1.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
  2. xsi:schemaLocation=&quot;http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd&quot;&gt;
  3. &lt;profiles&gt;
  4. &lt;profile&gt;
  5. &lt;id&gt;stefan&lt;/id&gt;
  6. &lt;activation&gt;
  7. &lt;activeByDefault&gt;true&lt;/activeByDefault&gt;
  8. &lt;/activation&gt;
  9. &lt;repositories&gt;
  10. &lt;repository&gt;
  11. &lt;id&gt;central&lt;/id&gt;
  12. &lt;url&gt;https://repo1.maven.org/maven2&lt;/url&gt;
  13. &lt;releases&gt;
  14. &lt;updatePolicy&gt;never&lt;/updatePolicy&gt;
  15. &lt;/releases&gt;
  16. &lt;snapshots&gt;
  17. &lt;enabled&gt;false&lt;/enabled&gt;
  18. &lt;/snapshots&gt;
  19. &lt;/repository&gt;
  20. &lt;repository&gt;
  21. &lt;id&gt;spring-milestones&lt;/id&gt;
  22. &lt;url&gt;https://repo.springsource.org/libs-milestone/&lt;/url&gt;
  23. &lt;releases&gt;
  24. &lt;updatePolicy&gt;never&lt;/updatePolicy&gt;
  25. &lt;/releases&gt;
  26. &lt;snapshots&gt;
  27. &lt;enabled&gt;false&lt;/enabled&gt;
  28. &lt;/snapshots&gt;
  29. &lt;/repository&gt;
  30. &lt;repository&gt;
  31. &lt;id&gt;jboss&lt;/id&gt;
  32. &lt;url&gt;https://repository.jboss.org/nexus/content/groups/public/&lt;/url&gt;
  33. &lt;releases&gt;
  34. &lt;updatePolicy&gt;never&lt;/updatePolicy&gt;
  35. &lt;/releases&gt;
  36. &lt;snapshots&gt;
  37. &lt;enabled&gt;false&lt;/enabled&gt;
  38. &lt;/snapshots&gt;
  39. &lt;/repository&gt;
  40. &lt;/repositories&gt;
  41. &lt;pluginRepositories&gt;
  42. &lt;pluginRepository&gt;
  43. &lt;id&gt;central&lt;/id&gt;
  44. &lt;url&gt;https://repo1.maven.org/maven2&lt;/url&gt;
  45. &lt;releases&gt;
  46. &lt;updatePolicy&gt;never&lt;/updatePolicy&gt;
  47. &lt;/releases&gt;
  48. &lt;snapshots&gt;
  49. &lt;enabled&gt;false&lt;/enabled&gt;
  50. &lt;/snapshots&gt;
  51. &lt;/pluginRepository&gt;
  52. &lt;/pluginRepositories&gt;
  53. &lt;/profile&gt;
  54. &lt;/profiles&gt;
  55. &lt;/settings&gt;

答案2

得分: 3

你必须将groupId放在artifactId之上。

  1. &lt;plugin&gt;
  2. &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  3. &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
  4. &lt;version&gt;3.3.0&lt;/version&gt;
  5. &lt;configuration&gt;
  6. &lt;archive&gt;
  7. &lt;manifest&gt;
  8. &lt;mainClass&gt;de.uulm.sp.pvs.sokoban.App&lt;/mainClass&gt;
  9. &lt;/manifest&gt;
  10. &lt;/archive&gt;
  11. &lt;descriptorRefs&gt;
  12. &lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
  13. &lt;/descriptorRefs&gt;
  14. &lt;/configuration&gt;
  15. &lt;/plugin&gt;
英文:

You have to put the groupId in above the artifactId.

  1. &lt;plugin&gt;
  2. &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  3. &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
  4. &lt;version&gt;3.3.0&lt;/version&gt;
  5. &lt;configuration&gt;
  6. &lt;archive&gt;
  7. &lt;manifest&gt;
  8. &lt;mainClass&gt;de.uulm.sp.pvs.sokoban.App&lt;/mainClass&gt;
  9. &lt;/manifest&gt;
  10. &lt;/archive&gt;
  11. &lt;descriptorRefs&gt;
  12. &lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
  13. &lt;/descriptorRefs&gt;
  14. &lt;/configuration&gt;
  15. &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:

确定