2014-07-22 89 views
1

我有一個多模塊項目,如下圖所示:Maven的SQL-插件運行在多模塊項目多次

  Module 
      |_________sub-module1 
      |     |___pom.xml   
      |_________sub-module2 
      |     |___pom.xml 
      |_________sub-module3 
      |     |___pom.xml 
      |_________sub-module4 
      |     |___pom.xml 
      |_________pom.xml 

我在子增加了對創建和刪除集成測試數據的一些SQL腳本模塊2。在父pom中,我有以下代碼來設置集成測試的數據庫。

<plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>sql-maven-plugin</artifactId> 
        <dependencies> 
         <dependency> 
          <groupId>net.sourceforge.jtds</groupId> 
          <artifactId>jtds</artifactId> 
          <version>1.3.1</version> 
         </dependency> 
        </dependencies> 

        <configuration> 
         <driver>net.sourceforge.jtds.jdbc.Driver</driver> 
         <url>jdbc:jtds:sqlserver:blah</url> 
         <settingsKey>sqlsrv-integration-test-creds</settingsKey> 
         <skip>false</skip> 
        </configuration> 

        <executions> 

         <execution> 
          <id>create-integration-test-data</id> 
          <phase>process-test-resources</phase> 
          <goals> 
           <goal>execute</goal> 
          </goals> 
          <configuration> 
           <orderFile>ascending</orderFile> 
           <fileset> 
            <basedir>${basedir}/src/test/resources</basedir> 
            <includes> 
             <include>create-integration-test-data.sql</include> 
            </includes> 
           </fileset> 
          </configuration> 
         </execution> 
         <execution> 
          <id>drop-db-after-test</id> 
          <phase>post-integration-test</phase> 
          <goals> 
           <goal>execute</goal> 
          </goals> 
          <configuration> 
           <fileset> 
            <basedir>${basedir}/src/test/resources</basedir> 
            <includes> 
             <include>drop-integration-test-data.sql</include> 
            </includes> 
           </fileset> 
          </configuration> 
         </execution> 

        </executions> 

</plugin> 

現在,當我運行mvn clean install,我得到的錯誤,該文件不子模塊1存在。所以我嘗試添加腳本到子模塊1。現在,它已在子模塊1中執行,但也在子模塊2子模塊3中執行,因爲腳本在子模塊3中不存在,所以它失敗。

如何讓腳本只執行一次?

+2

準確地將sql-maven-plugin添加到你需要它(子模塊-2)的地方,而不是在父級,因爲它會被繼承,當然會在每個孩子中執行。 – khmarbaise

回答

1

回答評論:

添加SQL-Maven的插件正是你需要它(子模塊-2)和 不在父,因爲它會被繼承,當然會 在每個孩子中執行。評論時間70年01月01日原作者:khmarbaise

相關問題