2

We do not need to specify the versions and other parameters of Maven dependencies and plugins we use. We can do it only once in parent POM or may be in some other way and inherit that properties in our children POMs.

Unfortunately for many times I have met the projects where I cannot find the real parameters of dependencies and plugins that easily. I.e. the versions of dependencies are empty, but in parent POM there is no information about this.

So my questions are:

  1. What are all the possible ways to specify the parameters of dependency and plugin in Maven? I.e. where can I look for version number if it is not present neither in plugin in child POM nor in plugin management in parent pom?

  2. Is there any Maven command to find out where Maven takes these parameters from? For example, I may use the dependency:tree command. It will print a list of dependencies which will help me to understand the version dependency I am stuck about. But this is a hack, and it cannot help me with plugins. May be there is something better?

4

1 回答 1

5

在执行任何命令之前,Maven 会构建“有效的 POM”,有关更多详细信息,请参阅此 stackoverflow 答案。您可以通过运行查看任何项目的有效 POM mvn help:effective-pom。通常,当我运行此命令时,我会将输出重定向到一个文件中,以便我可以在文本编辑器中查看和搜索它。

您询问了 POM、依赖项和插件的特定部分。您走在正确的轨道上,maven-dependency-plugin会有所帮助。我最常使用的目标是dependency:treedependency:resolvedependency:resolve-plugins。前两个辅助项目依赖,最后一个辅助插件。添加-U选项以强制 Maven 更新依赖项,而不管更新策略/存储库元数据值如何。

从空的本地存储库开始进行故障排除时也很有帮助。

最后但同样重要的是,当构建使用没有特定版本的插件时,Maven 会发出警告。始终指定一个明确的版本来修复警告并避免类似这样的问题。

于 2014-10-02T14:38:47.703 回答