且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法执行目标org.apache.maven.plugins:maven-jar-plugin:2.4:jar

更新时间:2021-10-03 16:58:54

让我澄清一下: dependencyManagement 部分为定义它的同一个POM和子/模块Maven项目提供依赖关系治理。
但是,在 dependencyManagement 部分声明依赖并不意味着Maven会使用它,它只是一个提示,以防Maven将使用它以便如果某个依赖项部分中缺少版本,Maven将在 dependencyManagement 部分中查找。如果没有找到,则会产生错误(Maven无法知道要为某个依赖项解析哪个版本)。

Let me clarify: the dependencyManagement section provide dependencies governance to the same POM where it is defined and to children/modules Maven projects. However, declaring a dependency in the dependencyManagement section doesn't mean Maven will use it, it's just an hint in case Maven will use it so that if a certain version is missing in the dependencies section, Maven will look it up in the dependencyManagement section. If none is found then, an error will be generated (Maven couldn't know which version to resolve for a certain dependency).

因此,很高兴有 dependencyManagement 用于治理的部分,但它应该始终定义每个依赖项的版本,否则它将是错失的机会并使您的构建更容易出错。

Hence, good to have the dependencyManagement section for governance, but it should always define versions of each dependency, otherwise it would be a missed opportunity and make your build more error-prone.

如果您需要所有已声明的依赖项并且只在同一个声明POM的范围内,那么您实际上可以避免在 dependenciesManagement 部分所有,只需要你的依赖项部分为每个声明的依赖项提供版本。

If you need all of the declared dependencies and only in the scope of the same declaring POM, then you can actually avoid to have a dependenciesManagement section at all and just have your dependencies section providing versions for each declared dependency.

在这种情况下,你使用的是你的父POM中的 dependenciesManagement 部分(我看到它有模块),你应该检查jar模块中是否声明了相同的依赖项(如果需要),否则它不会在构建期间使用。此外,您还应检查相关模块中是否声明了另一个 dependenciesManagement 部分,并在没有版本的情况下再次声明相同的依赖关系。

In this case, you are using a dependenciesManagement section in your parent POM (I see it has modules), you should then check if in the jar module the same dependency is declared (if required), otherwise it will not be used during its build. Moreover, you should also check whether another dependenciesManagement section is declared in the concerned module and re-declaring the same dependency again without version.

可以通过以下方式提供一些额外的帮助:

Some additional helps can be provided by:


  • 使用 -e运行Maven构建 - X flags

  • 运行 mvn依赖项:tree -Dincludes =< concern_group_id_here>

  • 上次更改选项,运行构建为 mvn依赖项:purge-local-repository clean install ,这可以在缓存损坏的情况下运行(错误应该是虽然不同)

  • Running your Maven build using the -e -X flags
  • Running mvn dependency:tree -Dincludes=<concerned_group_id_here>
  • Last change option, run your build as mvn dependency:purge-local-repository clean install, which can work in case of corrupted cache (error should be different though)