2013-10-21 83 views
0

當我執行mvn clean install時,我完全喪失瞭如何讓這3個執行執行。我知道他們在PluginManagement部分,我覺得這是問題的一部分。 感謝如何獲得這個pom.xml文件中的3個執行來執行?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <parent> 
     <groupId>jhu.rahLeague</groupId> 
     <artifactId>rahLeague</artifactId> 
     <version>0.0.1-SNAPSHOT</version> 
    </parent> 

    <groupId>jhu.rahLeagueImpl</groupId> 
    <artifactId>rahLeagueImpl</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>rahLeagueImpl</name> 


    <profiles> 
     <profile> 
      <id>testing</id> 
      <activation> 
       <property> 
        <name>!skipTests</name> 
       </property> 
      </activation> 


      <build> 
       <pluginManagement> 
        <plugins> 
         <plugin> 
          <groupId>org.codehaus.mojo</groupId> 
          <artifactId>hibernate3-maven-plugin</artifactId> 
          <version>${hibernate3-maven-plugin.version}</version> 
          <extensions>true</extensions> 
          <dependencies> 
           <dependency> 
            <groupId>org.hibernate</groupId> 
            <artifactId>hibernate-entitymanager</artifactId> 
            <version>${hibernate3.version}</version> 
           </dependency> 
          </dependencies> 
          <executions> 
           <execution> 
            <id>drop-db-before-test</id> 
            <phase>process-test-classes</phase> 
            <goals> 
             <goal>execute</goal> 
            </goals> 
            <configuration> 
             <autocommit>true</autocommit> 
             <fileset> 
              <basedir>${basedir}/src</basedir> 
              <includes> 
               <include>main/resources/ddl/*drop*.ddl</include> 
              </includes> 
             </fileset> 
             <onError>continue</onError> 
            </configuration> 
           </execution> 
           <execution> 
            <id>create-db-before-test</id> 
            <phase>process-test-classes</phase> 
            <goals> 
             <goal>execute</goal> 
            </goals> 
            <configuration> 
             <autocommit>true</autocommit> 
             <fileset> 
              <basedir>${basedir}/src</basedir> 
              <includes> 
               <include>main/resources/ddl/*create*.ddl</include> 
              </includes> 
             </fileset> 
             <print>true</print> 
            </configuration> 
           </execution> 
           <execution> 
            <id>populate-db-before-test</id> 
            <phase>process-test-classes</phase> 
            <goals> 
             <goal>execute</goal> 
            </goals> 
            <configuration> 
             <autocommit>true</autocommit> 
             <fileset> 
              <basedir>${basedir}/src</basedir> 
              <includes> 
               <include>test/resources/ddl/**/*populate*.ddl</include> 
              </includes> 
             </fileset> 
            </configuration> 
           </execution> 
           <!-- <execution> 
            <id>drop-db-after-test</id> 
            <phase>test</phase> 
            <goals> 
             <goal>execute</goal> 
            </goals> 
            <configuration> 
             <autocommit>true</autocommit> 
             <fileset> 
              <basedir>${basedir}/src</basedir> 
              <includes> 
               <include>main/resources/ddl/**/*drop*.ddl</include> 
              </includes> 
             </fileset> 
            </configuration> 
           </execution> --> 
          </executions> 
         </plugin> 
         <plugin> 
          <groupId>org.codehaus.mojo</groupId> 
          <artifactId>sql-maven-plugin</artifactId> 
          <version>${sql-maven-plugin.version}</version> 

          <dependencies> 
           <dependency> 
            <groupId>com.h2database</groupId> 
            <artifactId>h2</artifactId> 
            <version>${h2db.version}</version> 
           </dependency> 
          </dependencies> 

          <configuration> 
           <username>${jdbc.user}</username> 
           <password>${jdbc.password}</password> 
           <driver>${jdbc.driver}</driver> 
           <url>${jdbc.url}</url> 
          </configuration> 
         </plugin> 
        </plugins> 
       </pluginManagement> 

       <plugins> 
        <plugin> 
         <groupId>org.apache.maven.plugins</groupId> 
         <artifactId>maven-compiler-plugin</artifactId> 
         <version>3.1</version> 
         <configuration> 
          <source>1.7</source> 
          <target>1.7</target> 
         </configuration> 
        </plugin> 
       </plugins> 
      </build> 

     </profile> 
    </profiles> 


    <dependencies> 
     <dependency> 
      <groupId>joda-time</groupId> 
      <artifactId>joda-time</artifactId> 
      <version>2.3</version> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.8.1</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <version>1.2.17</version> 
     </dependency> 
     <dependency> 
      <groupId>commons-logging</groupId> 
      <artifactId>commons-logging</artifactId> 
      <version>1.1.3</version> 
     </dependency> 

     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-core</artifactId> 
      <version>4.2.6.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate.javax.persistence</groupId> 
      <artifactId>hibernate-jpa-2.0-api</artifactId> 
      <version>1.0.1.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-entitymanager</artifactId> 
      <version>4.2.6.Final</version> 
     </dependency> 
     <!-- <dependency> <groupId>org.hibernate.common</groupId> <artifactId>hibernate-commons-annotations</artifactId> 
      <version>4.0.4.Final</version> </dependency> --> 
     <dependency> 
      <groupId>com.h2database</groupId> 
      <artifactId>h2</artifactId> 
      <version>1.3.173</version> 
     </dependency> 
     <!-- <dependency> 
      <groupId>org.apache.cocoon</groupId> 
      <artifactId>cocoon-databases-hsqldb-client</artifactId> 
      <version>1.0.0</version> 
     </dependency> --> 


    </dependencies> 
</project> 
+1

看一看[簡介來創建個人資料](http://maven.apache.org/guides/ introduction/introduction-to-profiles.html),我覺得'mvn -P testing'應該可以工作 – atomman

回答

0

您還需要參考插件的配置文件的plugins部分(目前你只需要引用那裏maven-compiler-plugin)只是在pluginManagement部分,而不是。

所以,你的POM是:

... 
<profiles> 
    <profile> 
     <id>testing</id> 
     <activation> 
      <property> 
       <name>!skipTests</name> 
      </property> 
     </activation> 

     <build> 
      <pluginManagement> 
       <plugins> 
        <plugin> 
         <groupId>org.codehaus.mojo</groupId> 
         <artifactId>hibernate3-maven-plugin</artifactId> 
         <!-- excluded the configuration to keep this as short as possible --> 
         ... 
        </plugin> 
        <plugin> 
         <groupId>org.codehaus.mojo</groupId> 
         <artifactId>sql-maven-plugin</artifactId> 
         <!-- etc --> 
        </plugin> 
       </plugins> 
      </pluginManagement> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-compiler-plugin</artifactId> 
        ... 
       </plugin> 
       <!-- add hibernate3-maven-plugin here. Don't need to --> 
       <!-- define a version or configuration as that has  --> 
       <!-- already been done in the pluginManagement section --> 
       <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>hibernate3-maven-plugin</artifactId> 
       </plugin> 
       <!-- am presuming you would also want the sql-maven-plugin to run --> 
       <!-- so you would need to add it here as well      --> 
       <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>sql-maven-plugin</artifactId> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 

<dependencies> 
    ... 

一個POM(和配置文件)的標準plugins部分定義哪些插件應該在構建過程中執行的(以及如何根據自己的配置)。

pluginManagement部分還包含在大致相同的方式plugin元素,除了不是配置這個特定項目構建plugin信息,它的目的是配置項目的基礎,從這個繼承(可用於配置當前POM也是如此)。但是,這隻能配置plugin,實際上是在子元素中的plugins元素中引用的(或者當前的pom - 這是您的案例中缺少的元素)。兒童有權凌駕pluginManagement的定義。

所以一般你可以使用pluginManagement部分定義插件的標準配置,然後在子勁歌激活它(並覆蓋所需的任何配置)通過在聚甲醛的標準plugins部分引用的插件。

Maven的對POM文件可以在這裏找到:http://maven.apache.org/pom.html(可以解釋它比我好得多)

+0

ps不確定你使用的是什麼版本的hibernate3-maven-plugin,但版本3.0沒有執行目標。可用的目標是:hbm2doc,hbm2hbmxml,hbm2dao,查詢,工具,運行,hbmtemplate,hbm2cfgxml,hbm2ddl,help,hbmlint,hbm2java。我猜你可能想要'跑'的目標? – DB5