2017-07-25 152 views
0

我正在研究一个由父项目和子项目列表(模块)组成的Java EE项目。我已经宣布和<pluginmanagement>标签中配置父项目的pom.xml中一个插电式如下:我该如何执行一个在父pom.xml中声明的插件,放在Maven的特定子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> 

    ... 

然后,我已引用它的孩子的的pom.xml文件:

... 
<build> 
    <plugins> 
     <plugin> 
      <groupId>com.btmatthews.maven.plugins.inmemdb</groupId> 
      <artifactId>inmemdb-maven-plugin</artifactId> 
     </plugin> 
    </plugins> 
</build> 
... 

从我已阅读在互联网上,这似乎是潭里ght确保特定插件仅用于我引用它的特定模块上的方式。

但是,当我运行mvn install命令时,需要运行的插件根本不会显示出来。还有什么需要完成的,以便插件仅在特定模块上运行?

在此先感谢。

更新:我替换有效问卷错<phase>值,但仍当我附上插件与<pluginmanagement>插件不会运行在所有。

+0

你确定'预test'阶段是实际右相?你是指测试或预集成测试? 请参阅:https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html – gtosto

+0

@gtosto感谢您的快速响应,事情是,当即时通讯没有分配父母的阶段pom.xml,插件正常运行,但不是来自子模块。我会快速编辑,以免造成混淆。 :) –

回答

0

父级>子级配置看起来正确,即在父级中定义pluginManagement中的插件,然后通过将其包含在build/plugins中将其插入子级。但是这对我来说看起来不正确:<phase>pre-test</phase>,pre-test不是Maven生命周期中的有效阶段,并且将您的插件挂钩到不存在的阶段将阻止它运行。我认为正确的插件配置为:

<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> 

我怀疑你可能已经使用了“相”预测试和测试后,以启动和停止内存DB如/当你开始测试阶段和停止?如果是这样,那么正确的Maven的阶段是:

  • pre-integration-test
  • post-integration-test
+0

感谢您的快速响应。问题是,即时通讯运行一些简单的JUnit测试,而不是整合测试用例。这是否会改变你答案中的任何内容? @ glitch –

+0

在Maven构建生命周期中,对于简单前测试和后简化测试没有钩子。这些钩子只存在于“集成测试”中。所以,如果你想使用这个插件来启动和停止内存数据库作为测试阶段的一部分,那么我认为你将不得不使用'集成测试'。你可能想看看该插件的文档,看看是否有其他选择。然而,选择一个不存在的阶段(预测试)并不能达到你想要的,相反,选择一个不存在的阶段只会阻止Maven运行这个插件。 – glytching

+0

如果我使用'runDB'执行的Maven构建生命周期的'测试'阶段以及用于停止数据库的默认阶段?我读过“测试”阶段比“集成测试”更早运行......我会做出一些更改,如果那是解决方案,我会让你知道。 –