2010-10-17 138 views
3

我想从pom.xml依赖项生成类路径文件。我需要它,这样在测试过程中我都依赖关系(后打包成捆)的类路径使用Maven生成类路径文件

maven-dependency-plugin不适合我,原因有二:

  • 它生成的文件的路径在仓库中,所以要使用其他模块,他们首先需要为它们运行install阶段(我想要有像/some/root/othermodule/target/classes这样的路径)
  • 它不包含工件自己的路径(target/classes),这意味着我需要稍后添加它代码,很尴尬

所以我在寻找另一个插件(或如何正常运行maven-dependency-plugin

+0

测试的类路径是自动生成的。那么特定问题在哪里?或者你是在谈论一种集成测试而不是单元测试? (Multimodule build?) – khmarbaise 2010-10-17 12:37:06

+0

在一个组件中,我为另一个组件创建一个ClassLoader。在生产中,classpath是lib/*,但在测试中我不想通过打包 – IttayD 2010-10-17 13:19:58

回答

2

我最终使用GMaven:

 <plugin> 
      <groupId>org.codehaus.groovy.maven</groupId> 
      <artifactId>gmaven-plugin</artifactId> 
      <executions> 
       <execution> 
        <phase>generate-resources</phase> 
        <goals> 
         <goal>execute</goal> 
        </goals> 
        <configuration> 
         <source> 
          def all = project.runtimeArtifacts.collect{ 
           def aid = "${it.groupId}:${it.artifactId}:${it.version}" 
           def p = project.projectReferences[aid] 
           p?.build?.outputDirectory ?: it.file.path 
          } + project.build.outputDirectory 
          def file = new File(project.build.directory, ".classpath") 
          file.write(all.join(File.pathSeparator)) 
         </source> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

的代码,因为我想的路径来定位有点复杂/班如果可能。如果不需要,可以这样做:

file.write(project.runtimeClasspathElements.join(File.pathSeparator))