更新时间: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
,这可以在缓存损坏的情况下运行(错误应该是虽然不同)-e -X
flagsmvn dependency:tree -Dincludes=<concerned_group_id_here>
mvn dependency:purge-local-repository clean install
, which can work in case of corrupted cache (error should be different though)无法计算构建计划:无法解析插件 org.apache.maven.plugins:maven-jar-plugin:2.3.2 或其依赖项之一
无法执行目标org.apache.maven.plugins:项目中的maven-compiler-plugin(default-compile):致命错误编译:未找到tools.jar
无法读取org.apache.maven.plugins:maven-source-plugin:jar:2.4的工件描述符
从存储库中错误解析插件'org.apache.maven.plugins:maven-jar-plugin'的版本,在任何插件存储库中均未找到插件
目标org.apache.maven.plugins执行attach-javadocs:maven-javadoc-plugin:3.0.0:jar使用Java10失败
无法使用带有错误的MAVEN构建 - 无法执行目标org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
无法执行目标org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile(default-compile)
Maven无法执行目标org.apache.maven.plugins:maven-clean-plugin:2.5:clean无法删除access_log
Maven构建编译错误:无法执行目标org.apache.maven.plugins:maven-compiler-plugin:3.1:在项目Maven上编译(default-compile)