2012-09-12 57 views
9

我试图用下面的pom部分向我的maven生命周期添加一个目标。我定义了一个新的插件,并使用相位和执行信息进行配置。为什么我的Maven插件不能在构建生命周期中运行?

<build> 
    <pluginManagement> 
     <plugins>     
      <plugin> 
       <groupId>org.apache.openjpa</groupId> 
       <artifactId>openjpa-maven-plugin</artifactId> 
       <version>2.2.0</version> 
       <configuration> 
       <includes>**/entity/*.class</includes> 
       <addDefaultConstructor>true</addDefaultConstructor> 
       <connectionDriverName>com.ibm.db2.jcc.DB2Driver</connectionDriverName> 
         <enforcePropertyRestrictions>true</enforcePropertyRestrictions> 
         <sqlFile>${project.build.directory}/database.sql</sqlFile> 
        </configuration> 
        <executions> 
         <execution> 
          <id>sql</id> 
          <phase>generate-resources</phase> 
          <goals> 
           <goal>sql</goal> 
          </goals> 
         </execution> 
         <execution> 
          <id>enhancer</id> 
          <phase>process-classes</phase> 
          <goals> 
           <goal>enhance</goal> 
          </goals> 
         </execution> 
        </executions> 
        <dependencies> 
         <dependency> 
          <groupId>org.apache.openjpa</groupId> 
          <artifactId>openjpa</artifactId> 

          <version>2.1.1</version> 
         </dependency> 
        </dependencies> 
       </plugin> 
      </plugins> 
     </pluginManagement> 
    </build> 

然后我用mvn:install运行maven但是插件没有运行?

+0

@帕 - thivent任何想法的建设 - >插件部分? – Kayser

+0

默认情况下,sql mojo绑定到“进程类”阶段。 也许这个目标不起作用,因为你试图在构建生命周期中过早运行它? – wemu

+0

只是在尝试获取插件时遇到一个主要的问题。它被定义了两次,第二个定义覆盖了第一个定义。 – doc

回答

16

确保插件存在依赖关系,并且该插件位于build/plugin而不是build/pluginmanagement/plugin

尝试用这样的事情:

<dependencies> 
    <dependency> 
     <groupId>org.apache.openjpa</groupId> 
     <artifactId>openjpa</artifactId> 
     <version>2.1.1</version> 
    </dependency> 
</dependencies> 

<build> 
    <pluginManagement> 
     <plugins>     
      <plugin> 
       <groupId>org.apache.openjpa</groupId> 
       <artifactId>openjpa-maven-plugin</artifactId> 
       <version>2.2.0</version> 
       <configuration> 
        <includes>**/entity/*.class</includes> 
        <addDefaultConstructor>true</addDefaultConstructor> 
        <connectionDriverName>com.ibm.db2.jcc.DB2Driver</connectionDriverName> 
        <enforcePropertyRestrictions>true</enforcePropertyRestrictions> 
        <sqlFile>${project.build.directory}/database.sql</sqlFile> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 

    <plugins> 
     <plugin> 
      <groupId>org.apache.openjpa</groupId> 
      <artifactId>openjpa-maven-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>sql</id> 
        <phase>generate-resources</phase> 
        <goals> 
         <goal>sql</goal> 
        </goals> 
       </execution> 
       <execution> 
        <id>enhancer</id> 
        <phase>process-classes</phase> 
        <goals> 
         <goal>enhance</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 
+0

不,它不起作用。 – Kayser

+0

我必须道歉。我错过了第二部分。我现在试了一下。一切按预期工作 – Kayser

+0

很高兴它现在排序。 – Farid

9

pluginManagement是应该配置的插件,这是在命令行调用。

如果你要绑定插件一些执行阶段 - 只需将其移动到你的pom.xml

相关问题