2014-11-03 38 views
0

我是Maven的新手,我試圖對現有項目進行一些改進。 我相信有一種有效的方式來建立一個參數配置文件或以某種方式減少任務的線路大小。如何最小化Maven POM.XML文件

中的當前配置是建立像這樣的:

<profile> 
     <id>green</id> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>com.smart.soapui</groupId> 
        <artifactId>soapui-pro-maven-plugin</artifactId> 
        <version>5.1.2</version> 
        <configuration> 
         <projectFile>resources/api/API-NEW-automation.xml</projectFile> 
         <junitReport>true</junitReport> 
         <reportName>sanity-api</reportName> 
         <printReport>true</printReport> 
         <reportFormat>HTML</reportFormat> 
         <outputFolder>target</outputFolder> 
         <projectProperties> 
          <value>message=Running API Sanity test</value> 
         </projectProperties> 
        </configuration> 
       </plugin> 
       <plugin> 
        <artifactId>maven-antrun-plugin</artifactId> 
        <executions> 
         <execution> 
          <phase>validate</phase> 
          <goals> 
           <goal>run</goal> 
          </goals> 
          <configuration> 
           <tasks> 
            <delete file="src/main/resources/config.properties" /> 
            <copy file="src/main/resources/green/config.properties" 
             tofile="src/main/resources/config.properties" /> 
            <delete file="src/main/resources/TestData.properties" /> 
            <copy file="src/main/resources/green/TestData.properties" 
             tofile="src/main/resources/TestData.properties" /> 
            <delete file="src/main/resources/loginTestData.csv" /> 
            <copy file="src/main/resources/green/loginTestData.csv" 
             tofile="src/main/resources/loginTestData.csv" /> 
            <delete file="src/main/resources/browsingTestData.csv" /> 
            <copy file="src/main/resources/green/browsingTestData.csv" 
             tofile="src/main/resources/browsingTestData.csv" /> 
            <delete file="src/main/resources/endUsersDetails.csv" /> 
            <copy file="src/main/resources/green/endUsersDetails.csv" 
             tofile="src/main/resources/endUsersDetails.csv" /> 
           </tasks> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 

由於每一個配置有這些任務(而且有超過所示)我雖然使用通用代碼。你們有沒有經歷過類似的事情?

謝謝。

+1

如果我理解正確,你正在尋找一個POM繼承方案,它已經存在。請參閱[本文檔](http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Project_Inheritance) – 2014-11-03 09:18:11

+0

您應該避免修補src文件夾內的文件。這裏的所有數據都可能連接到SCM,因此每個構建都會引入更改。相反,maven處理目標文件夾內的文件夾,例如生成源代碼,您可以在每次生成運行時放置數據。 – wumpz 2014-11-03 10:02:58

回答

1

您可以通過編寫自己的自定義Ant任務(將簡檔ID也作爲參數傳遞)並將路徑外部化爲屬性文件來實現此目的。然後,您可以在每個配置文件中單獨調用自定義ant任務。鏈接如何編寫自定義螞蟻任務可以發現here