2012-04-27 67 views
0

我正在編寫一個JAR文件,充當Jenkins CI webapp的客戶端。因此,我的項目有罐裝包裝,而不是戰爭包裝。但是,對於集成測試,我需要部署Jenkins WAR來測試我的JAR類。Maven:無法在預集成測試和後整合測試階段啓動JAR項目上的插件

我使用的貨物maven2的-插件,並將它設置,使我可以用下面的命令行啓動詹金斯「MVN貨:運行」但是,在運行「MVN安裝」進入集成測試階段沒有試圖用貨運發射詹金斯。事實上,「mvn install -X」的輸出甚至沒有提到「貨物」這個詞。

它看起來像我已經正確地將貨物綁定到預集成測試和整合後測試,但它不會觸發。

POM如下:

<?xml version="1.0" encoding="UTF-8"?> 
<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> 
<groupId>com.phoenix.build</groupId> 
<artifactId>HostOp</artifactId> 
<packaging>jar</packaging> 
<version>0.0.1-SNAPSHOT</version> 
<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <jetty.port>53657</jetty.port><!-- mnemonic: 'JENKS' on a telephone --> 
</properties> 
<name>Host Operations</name> 
<build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.7.2</version> 
       <configuration> 
        <systemProperties> 
         <property> 
          <name>maven.output.dir</name> 
          <value>${project.build.directory}</value> 
         </property> 
        </systemProperties> 
        <excludes> 
         <exclude>**/*IntegrationTest.java</exclude> 
        </excludes> 
       </configuration> 
       <executions> 
        <execution> 
         <id>integration-tests</id> 
         <phase>integration-test</phase> 
         <goals> 
          <goal>test</goal> 
         </goals> 
         <configuration> 
          <skip>false</skip> 
          <excludes> 
           <exclude>none</exclude> 
          </excludes> 
          <includes> 
           <include>**/*IntegrationTest.java</include> 
          </includes> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.codehaus.cargo</groupId> 
       <artifactId>cargo-maven2-plugin</artifactId> 
       <executions> 
        <execution> 
         <id>start-container</id> 
         <phase>integration-test</phase> 
         <goals> 
          <goal>start</goal> 
         </goals> 
        </execution> 
        <execution> 
         <id>stop-container</id> 
         <phase>post-integration-test</phase> 
         <goals> 
          <goal>stop</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <container> 
         <containerId>jetty6x</containerId> 
         <type>embedded</type> 
         <systemProperties> 
          <JENKINS_HOME>target/test-classes/jenkins_home</JENKINS_HOME> 
         </systemProperties> 
        </container> 
        <configuration> 
         <properties> 
          <cargo.servlet.port>53657</cargo.servlet.port> 
          <cargo.jvmargs>-DJENKINS_HOME=target/test-classes/jenkins_home</cargo.jvmargs> 
         </properties> 
         <deployables> 
          <deployable> 
           <type>war</type> 
           <location>target/test-classes/jenkins.war</location> 
           <pingURL>http://localhost:53657/jenkins/view/All/newJob</pingURL> 
          </deployable> 
         </deployables> 
        </configuration> 
       </configuration> 
      </plugin> 
     </plugins> 
</build> 
<dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.8.2</version> 
    </dependency> 
</dependencies> 
</project> 

我怎樣才能得到這個火需要?

+0

您確定您的/ project/build/plugins元素中有插件,並且沒有意外嵌套在配置文件中嗎?這比我能算的更多次,但我仍然會這樣做。 – 2012-04-27 17:49:45

+0

對不起,它在。不過,好想法。 – 2012-04-27 17:57:32

+0

你可以發佈一個POM修剪到只有你看到的方式失敗的貨物插件嗎? – 2012-04-27 18:13:54

回答

1

您發佈的pom按預期工作。我只是將它扔進一個空項目,以及:

$ mvn install 
[...] 
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ cargo-plugin-test --- 
[...] 
[INFO] --- maven-surefire-plugin:2.7.2:test (integration-tests) @ cargo-plugin-test --- 
[...] 
[INFO] --- cargo-maven2-plugin:1.2.1:start (start-container) @ cargo-plugin-test --- 
[INFO] [2.ContainerStartMojo] Resolved container artifact org.codehaus.cargo:cargo-core-container-jetty:jar:1.2.1 for container jetty6x 
[INFO] [beddedLocalContainer] Jetty 6.x Embedded starting... 
[...] 
2012-04-27 15:01:02.457:WARN::Web application not found target/test-classes/jenkins.war 
2012-04-27 15:01:02.457:WARN::Failed startup of context 
[...] 
2012-04-27 15:01:02.741:INFO::Started [email protected]:53657 
[INFO] [beddedLocalContainer] Jetty 6.x Embedded started on port [53657] 
[...] 

這與Maven 3.0.3是:

$ mvn --version 
Apache Maven 3.0.3 (r1075438; 2011-02-28 11:31:09-0600) 
Maven home: /home/ryan/dev/tools/maven 
Java version: 1.7.0_03, vendor: Oracle Corporation 
Java home: /home/ryan/dev/tools/jdk1.7.0_03/jre 
Default locale: en_US, platform encoding: UTF-8 
OS name: "linux", version: "3.0.0-17-generic", arch: "amd64", family: "unix" 

我不知道它可能是什麼。

+0

我正在使用相同的Maven版本。如果我擺脫了我的集成測試(rm /src/test/java/com/phoenix/build/jenkins/*IntegrationTest.java),那麼Cargo將啓動並關閉。所以它顯然只在我實際上不需要時才起作用。 – 2012-04-27 20:26:03

+0

太棒了。 – 2012-04-27 22:00:21

+0

它變得更好。我發現如果我寫了一個沒有做任何事情的測試,然後把剩下的測試清除掉,我可以讓Cargo發佈。所以我拿了我的其他測試之一,評論一切,然後一個一個的評論。有一個地方,測試運行一個半無限循環(一段時間(真),並在裏面休息)。只要保持半無限,Cargo不會啓動。如果我把它作爲一個有限的循環與計數器,它將啓動貨物。預集成測試階段如何取決於代碼本身? – 2012-05-01 20:14:12