2012-05-21 69 views
0

我终于成功地让Maven使用程序集文件将一堆jar压缩到一起并将其安装到我的本地存储库。这很难......从maven zip组件运行测试

现在我的目标是配置另一个maven项目,这样当我做“mvn测试”时,它将拉入该zip文件,解压缩它,并从该zip文件中的罐子运行测试。有谁知道如何做到这一点?

下面是组装项目的POM:

<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/maven-v4_0_0.xsd"> 

<modelVersion>4.0.0</modelVersion> 
<groupId>com.pason</groupId> 
<artifactId>RigFocusOnDataHub</artifactId> 
<name>RigFocusOnDataHub</name> 
<version>12.2.0-SNAPSHOT</version> 
<packaging>pom</packaging> 

<dependencies> 
    ... 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.3</version> 
      <configuration> 
       <descriptors> 
        <descriptor>RigFocusOnDH.xml</descriptor> 
       </descriptors> 
      </configuration> 
      <executions> 
       <execution> 
        <id>zip</id> 
        <!-- this is used for inheritance merges --> 
        <phase>package</phase> 
        <!-- append to the packaging phase. --> 
        <goals> 
         <goal>single</goal> 
         <!-- goals == mojos --> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

这里是第二个项目的POM。不幸的是,它并没有下载RigFocusOnDataHub的zip文件,而是从本地仓库获取所有RigFocusOnDataHub依赖关系的jar包。

<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.pason</groupId> 
<artifactId>RigFocusDHSystemTest</artifactId> 
<version>12.2.0-SNAPSHOT</version> 
<dependencies> 
    <dependency> 
     <groupId>com.pason</groupId> 
     <artifactId>MurphyRigFocus</artifactId> 
     <version>2.0.0-SNAPSHOT</version> 
     <type>test-jar</type> 
    </dependency> 
    <dependency> 
     <groupId>com.pason</groupId> 
     <artifactId>RigFocusOnDataHub</artifactId> 
     <version>12.2.0-SNAPSHOT</version> 
     <type>pom</type> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.8.2</version> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>unpack</id> 
        <phase>process-test-classes</phase> 
        <goals> 
         <goal>unpack</goal> 
        </goals> 
        <configuration> 
         <artifactItems> 
          <artifactItem> 
           <groupId>com.pason</groupId> 
           <artifactId>MurphyRigFocus</artifactId> 
           <version>2.0.0-SNAPSHOT</version> 
           <type>test-jar</type> 
           <outputDirectory>${project.build.directory}/tests/MurphyRigFocus</outputDirectory> 
          </artifactItem> 
          <artifactItem> 
           <groupId>com.pason</groupId> 
           <artifactId>RigFocusOnDataHub</artifactId> 
           <version>12.2.0-SNAPSHOT</version> 
           <type>zip</type> 
           <outputDirectory>${project.build.directory}/tests/MurphyRigFocus</outputDirectory> 
          </artifactItem> 
         </artifactItems> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.6</version> 
      <configuration> 
       <testClassesDirectory>${project.build.directory}/tests/MurphyRigFocus</testClassesDirectory> 
       <reportsDirectory>${project.build.directory}/surefire-reports/MurphyRigFocus</reportsDirectory> 
       <includes> 
        <include>**/*IT.*</include> 
       </includes> 
       <argLine>-Djava.library.path=${basedir}/target/classes/</argLine> 
       <forkMode>pertest</forkMode> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

+0

为什么不把测试作为构建周期的一部分(在组装大型.jar之前)? – Attila

+0

这听起来像你需要有一个单独的集成测试模块,处理所有的集成测试的东西,多模块生成。 – khmarbaise

+0

您尝试使用maven-surefire插件来运行集成测试,这不是maven-surefire插件的意图。对于集成测试,使用maven-failsafe插件。 – khmarbaise

回答

1

你将需要:

  1. 从zip提取罐 - 这是Maven的依赖关系的插件很容易
  2. 切传递依赖让你的罐子不要”最终在路径中两次 - 你可以在maven-shade-plugin的源代码中或者在测试项目本身中执行相关性排除
  3. 将jar添加到你的tes t类路径,有很多方法可以做到这一点,我会尝试在surefire配置中首先使用其他参数