2011-06-03 99 views
0

嘿,我在談論項目的pom.xml中的配置文件。可以請任何人向我解釋,爲什麼如果我在pom定義中有2個配置文件,並且我從其中一個配置文件運行測試階段,那麼Main方法都會執行並且所有測試都由surefire插件運行?我的意思是,即使是安全火狐插件運行所有的測試,即使它在一個不同的配置文件?如何正確設置多配置文件maven項目?

mvn test -Pcode-generator 

第一個,代碼生成器,僅用於Main方法執行,第二個用於其餘項目。

<profiles> 
    <profile> 
     <id>code-generator</id> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>exec-maven-plugin</artifactId> 
        <version>1.1.1</version> 
        <executions> 
         <execution> 
          <phase>test</phase> 
          <goals> 
           <goal>java</goal> 
          </goals> 
          <configuration> 
           <mainClass>cz.instance.transl.Main</mainClass> 
           <arguments> 
            <argument>arg0</argument> 
            <argument>arg1</argument> 
           </arguments> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 

    <profile> 
     <id>default</id> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-war-plugin</artifactId> 
        <version>2.1</version> 
        <configuration> 
         <warName>${war.file.name}</warName> 
        </configuration> 
       </plugin> 

       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <version>2.7</version> 
        <configuration> 
         <useFile>false</useFile> 
         <argLine>-Dportal.test=generic 
          -Dwebdriver.chrome.driver="/opt/google/chrome/chromedriver" 
          -Dwebdriver.development=true 
          -Dwebdriver.firefox.useExisting=true 
          -Dwebdriver.firefox.profile=webdriver 
          -Dwebdriver.reap_profile=true 
          -Dsurefire.useFile=false 
          -Xmx2048M 
          -XX:MaxPermSize=1048M 
          -XX:+CMSClassUnloadingEnabled 
       </argLine> 
         <skipTests>false</skipTests> 

         <suiteXmlFiles> 
          <suiteXmlFile>${basedir}/src/test/resources/testng.xml</suiteXmlFile> 
         </suiteXmlFiles> 

         <systemProperties> 
          <property> 
           <name>log4j.configuration</name> 
           <value>META-INF/log4j.xml</value> 
          </property> 
         </systemProperties> 

         <includes> 
          <include>cz/instance/transl/tests/selenium/*Test.java</include> 
         </includes> 
         <excludes> 
          <exclude>cz/instance/transl/tests/sample/*Test.java</exclude> 
         </excludes> 
        </configuration> 
       </plugin> 

       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-report-plugin</artifactId> 
        <version>2.7.1</version> 
        <!-- <configuration> <useFile>false</useFile> </configuration> --> 
       </plugin> 

       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-compiler-plugin</artifactId> 
        <version>2.3.2</version> 
        <configuration> 
         <encoding>UTF-8</encoding> 
         <source>1.5</source> 
         <target>1.5</target> 
        </configuration> 
       </plugin> 
      </plugins> 

      <testResources> 
       <testResource> 
        <directory>${project.basedir}/src/test/java</directory> 
        <includes> 
         <include>**/*.*</include> 
        </includes> 
       </testResource> 
       <testResource> 
        <directory>${project.basedir}/src/test/resources</directory> 
        <includes> 
         <include>**/*</include> 
        </includes> 
       </testResource> 
      </testResources> 

      <resources> 
       <resource> 
        <directory>${project.basedir}/src/main/java</directory> 
        <includes> 
         <include>**/*.java</include> 
         <include>service.properties</include> 
        </includes> 
       </resource> 
       <resource> 
        <directory>${project.basedir}/src/main/resources</directory> 
        <includes> 
         <include>**/*.xml</include> 
         <include>**/*.properties</include> 
         <include>profiles/*</include> 
        </includes> 
       </resource> 
      </resources> 
     </build> 
    </profile> 
</profiles> 

回答

2

surefire插件是默認爲java項目運行的插件。您有多種選擇:

  • 將surefire插件添加到code-generator配置文件並覆蓋它不運行。
  • -DskipTests運行。
  • 僅指定要運行的目標,而不是運行完整的Maven構建。
+0

但我不能運行$ mvn test:java -PprofileName,對吧?如果它是「$ mvn somePlugin:java」,而不是phase:java,那麼可以這樣做。我如何指定它? – lisak 2011-06-03 14:25:12

+1

我想你可能不會使用Maven,因爲它應該是。 '代碼生成器'聽起來像是應該綁定到'生成源代碼'階段。它慢或什麼? – artbristol 2011-06-03 14:27:11

+0

它只是一個簡單的程序,駐留在Main方法中。與代碼/源代碼無關 – lisak 2011-06-03 14:28:52

相關問題