[英]How can I execute a plug-in, declared on parent pom.xml, on a spesific child pom.xml in Maven?
I am working on a Java EE project that consists of a parent project, and a list of sub-projects (modules). 我正在一个Java EE项目中,该项目由一个父项目和一个子项目(模块)列表组成。 I have declared and configured a plug-in on the parent project's pom.xml within a
<pluginmanagement>
tag as follows: 我已经在
<pluginmanagement>
标记内的父项目的pom.xml上声明并配置了一个插件,如下所示:
Parent pom.xml 父pom.xml
...
<pluginManagement>
<plugins>
<!-- inmem-db-plugin -->
<plugin>
<groupId>com.btmatthews.maven.plugins.inmemdb</groupId>
<artifactId>inmemdb-maven-plugin</artifactId>
<version>${version.inmemdb-plugin}</version>
<inherited>true</inherited>
<executions>
<execution>
<id>runDB</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
<monitorKey>inmemdb</monitorKey>
<monitorPort>11527</monitorPort>
<daemon>true</daemon>
<type>derby</type>
<database>localDB</database>
<username>${user}</username>
<password>${pass}</password>
<sources>
<script>
<sourceFile> create - data.sql </sourceFile>
<sourceFile> create - table.sql </sourceFile>
</script>
</sources>
</configuration>
</execution>
<execution>
<id>stopDB</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
...
And then I have referenced it on the child's pom.xml file: 然后在孩子的pom.xml文件中引用了它:
...
<build>
<plugins>
<plugin>
<groupId>com.btmatthews.maven.plugins.inmemdb</groupId>
<artifactId>inmemdb-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
...
From what I have read on the internet, this seems to be the right way of making sure that the specific plug-in will be used only on the specific module that i have referenced it. 从我在Internet上阅读的内容来看,这似乎是确保特定插件仅在我引用过的特定模块上使用的正确方法。
But, When I run the mvn install
command, the plug-in that it is needed to run wont show up at all. 但是,当我运行
mvn install
命令时,运行该插件所需的插件根本不会显示。 Is there anything else that it is needed to be done, in order for the plug-in to run on a spesific module only? 为了使插件仅在特殊的模块上运行,是否还需要做其他事情?
Thanks in advance. 提前致谢。
UPDATE: I replaced the wrong <phase>
values with valid ones, but still when I enclose the plugin with <pluginmanagement>
the plugin wont run at all. 更新:我用有效的值替换了错误的
<phase>
值,但是当我用<pluginmanagement>
封闭插件时,插件<pluginmanagement>
不会运行。
The parent > child configuration looks correct ie define the plugin in pluginManagement
in the parent and then engage it in the child by including it build/plugins
. parent> child配置看起来是正确的,即在
pluginManagement
中的父级中定义插件,然后通过包含build/plugins
使其参与子级。 But this looks incorrect to me: <phase>pre-test</phase>
, pre-test
is not a valid phase in the Maven lifecycle and hooking your plugin up to a non existent phase will prevent it from being run. 但这对我来说似乎是不正确的:
<phase>pre-test</phase>
, pre-test
在Maven生命周期中不是有效的阶段,将您的插件挂接到一个不存在的阶段将阻止其运行。 I think the correct plugin configuration is: 我认为正确的插件配置是:
<plugin>
<groupId>com.btmatthews.maven.plugins.inmemdb</groupId>
<artifactId>inmemdb-maven-plugin</artifactId>
<version>${version.inmemdb-plugin}</version>
<inherited>true</inherited>
<executions>
<execution>
<id>runDB</id>
<goals>
<goal>run</goal>
</goals>
<configuration>
...
</configuration>
</execution>
</executions>
</plugin>
I suspect you might have been using the 'phases' pre-test and post-test to start and stop the in-memory DB as/when your test phase starts and stops? 我怀疑您可能在测试阶段开始和停止时/开始使用“阶段”预测试和后测试来启动和停止内存数据库? If so, then the correct Maven phases are:
如果是这样,那么正确的Maven阶段是:
pre-integration-test
post-integration-test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.