2011-11-21 216 views
5

如何构建包含测试类和测试依赖项的jar(使用maven)。创建具有依赖性和测试依赖性的jar

我知道如何为'main'类的类和依赖关系创建一个具有依赖关系的jar(使用assembly插件),但我需要测试类和测试依赖关系。

我知道我可以使用jar插件创建一个包含测试类的jar,但是这不包含测试依赖关系。

TIA

回答

1

您可以通过将Maven的依赖,插件可能实现:copyDependencies与组装插件。

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <executions> 
    <execution> 
     <id>copy-dependencies</id> 
     <phase>process-resources</phase> 
     <goals> 
     <goal>copy-dependencies</goal> 
     </goals> 
     <configuration> <!-- by default all scopes are included --> 
     <!-- copy all deps to target/lib --> 
     <outputDirectory>${project.build.directory}/lib</outputDirectory> 
     </configuration> 
    </execution> 
    </executions> 
</plugin> 
<plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    ... 
</plugin> 

你的描述:

<assembly> 
    <fileSets> 
    <fileSet> 
     <directory>${project.build.directory}/lib</directory> 
     <outputDirectory>/</outputDirectory> 
     <includes> 
     <include>*.*</include> 
     </includes> 
    </fileSet> 
    </fileSets> 
</assembly> 
+0

谢谢,这个作品OKE。我确实需要这些类,所以我将使用解压缩依赖关系 – thehpi

+0

太好了,欢迎 –

+0

调查了一下程序集插件后,我发现我可以定义一个scope = test和unpack = true的dependencySet。这实际上和依赖插件一样。 – thehpi