2012-09-12 56 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

相關問題