11

我正在分析一个可以在以下configuration部分配置的 Maven 插件plugin

<plugin>
     ...
     <executions>...</executions>
     <configuration>
         <!-- items placed here are visible to the MOJO -->
     </configuration>
</plugin>

该插件完全忽略 的任何配置项execution,但是:

<plugin>
     ...
     <executions>
         <execution>
             <id>execution1</id>
             <phase>test</phase>
             <goals><goal>test</goal></goals>
             <configuration>
                <!-- items placed here are ignored -->
             </configuration>
         </execution>
     </executions>
</plugin>

我用mvn test. 我确定执行会发生,因为 Mavenid正确打印了它,但未配置插件 - 打印有关不正确设置的警告,当该<configuration>部分移出<executions>.

问题:是插件的实现方式,它只接受“顶级”配置吗?我研究了它的源代码,在我看来,它是 Maven 调用 MOJO 类上的设置器,并且它对于选项来自哪个部分的插件是透明的。

MOJO 注释为:

* @component
* @goal test
* @phase test
* @execute phase="jasmine-process-test-resources"
4

2 回答 2

4

有问题的插件正在分叉自定义生命周期。

分叉的自定义生命周期将execution1删除指定 id ( ) 的执行(因为它是一个分叉的生命周期)

因此,由分叉生命周期执行的任何插件目标都将丢失它们的配置。主要的 mojo 本身应该获取配置,但出了问题的是分叉的生命周期执行。

我猜它是哪个插件,如果我的猜测是正确的,这是自定义生命周期,您看到的警告来自例如其他带有类似文本的mojos

JavaScript source folder was expected but was not found. Set configuration property
`jsSrcDir` to the directory containing your JavaScript sources. Skipping 
jasmine:resources processing.

在这种情况下,您需要将该<configuration>部分放在外部块中或配置生命周期的执行。

为生命周期配置执行将需要使用id魔法格式的 s 添加执行。我不是 100% 确定,但在您的情况下,您将定义一个额外的执行,使用idsdefault-resources或sjasmine-lifecycle-resources以确保配置成功。

不太冗长的方法是将配置放在外部并完成它。

于 2013-01-29T15:15:09.480 回答
0

I had this issue with the base maven-install-plugin:2.5.2 using the maven:3.6.3-jdk-8 docker image.

Thanks to the accepted answer for putting me on the right track.

I don't fully understand this note in the documentation (at the end of the section), but it seems that you can give the phase goal an execution id forcing it to use your configuration:

Note: Configurations inside the element used to differ from those that are outside in that they could not be used from a direct command line invocation because they were only applied when the lifecycle phase they were bound to was invoked. So you had to move a configuration section outside of the executions section to apply it globally to all invocations of the plugin. Since Maven 3.3.1 this is not the case anymore as you can specify on the command line the execution id for direct plugin goal invocation. Hence if you want to run the above plugin and it's specific execution1's configuration from the command-line, you can execute:

mvn myqyeryplugin:queryMojo@execution1

My final working docker command:

docker run -it --rm --name parser -v "$(shell pwd)":/usr/src/parser -w /usr/src/parser maven:3.6.3-jdk-8 mvn -X install:install-file@install-my-jar-file

Where install-my-jar-file is my executions id <execution><id>install-my-jar-file</id>...

于 2021-03-25T01:46:53.290 回答