我正在尝试将 maven-license-plugin 的 mycila 版本 添加到遗留项目的根模块中:
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>4.3</version>
<configuration>...</configuration>
<executions>
<execution>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
当我尝试使用命令
mvn license:format
运行它时,出现错误 Could not find goal 'format' in plugin org.codehaus.mojo:license-maven-plugin:2.4.0 among available goals
。
我的工作区中的任何位置都没有定义
org.codehaus.mojo
的 license-maven-plugin
版本。事实上,工作区中的任何 pom.xml 中都不存在 codehaus
一词。
我的模块都没有在其依赖关系层次结构中找到
codehaus
,如果我运行 mvn org.apache.maven.plugins:maven-dependency-plugin:3.6.3:resolve-plugins
,则唯一列出的 license-maven-plugin
依赖关系是 com.mycila
,如预期的那样。该列表中有一些 org.codehaus.plexus
依赖项,但没有 org.codehaus.mojo
。
如果我从本地 .m2 目录中删除所有
codehaus
依赖项,运行 mvn license:format
会重新下载 license-maven-plugin
和 mojo-parent
,稍后 animal-sniffer-parent
和 animal-sniffer-annotations
也会出现。
如果我用
mvn license:format
运行 -X
,它会告诉我 [DEBUG] Resolving plugin prefix license from [org.apache.maven.plugins, org.codehaus.mojo]
,单词 mycila
不会出现在日志中的任何位置。
就我而言,问题是遗留项目的结构有点奇怪。根模块 pom.xml 列出了
<modules>
,但这些模块没有将根模块定义为其父模块。因为列出的模块在根模块之前得到解析,并且它们没有定义任何 license-maven-plugin
,所以它们尝试回退到 codehaus
版本,而不会抛出任何有关缺少定义的错误。然后,在到达具有插件定义的根模块之前,构建就会失败。
我不太清楚为什么选择
org.codehaus.mojo
作为解决目标前缀的选项,它肯定不是从super-pom继承的。我现在没有时间深入研究这个问题,但显然它确实发生了。
删除
<modules>
或在每个模块中定义插件即可解决问题。据推测,这样做可以使根模块成为每个模块的实际父模块,但由于不相关的原因,这在我的项目中目前是不可能的。