Maven: Extract dependency resources before test

心不动则不痛 提交于 2019-12-21 12:22:11

问题


I have a multimodule Maven project. One subproject hosts XSL/XML resource files. The other project hosts Java code that needs to use these files in its unit tests.

In the dependency's jar, the resources lie in the folder xml-resources.

I found this example and tried to change it for my needs:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>2.4</version>
  <executions>
    <execution>
      <id>resource-dependencies</id>
      <phase>process-test-resources</phase>
      <goals>
        <goal>unpack-dependencies</goal>
      </goals>
      <configuration>
        <classifier>xml-resources</classifier>
        <outputDirectory>${project.build.directory}/classes/xml-resources</outputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>

This doesn't do anything when I run the process-test-resources phase. Am am sure that there are some errors in there - I do not see where I can specify the dependency the resources should be taken from, and <classifier> does not seem to actually specify the source where the resources should be copied from.

I'm lost here, can somebody tell me how to do this right?


回答1:


Try something like this

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>2.4</version>
  <executions>
    <execution>
      <id>resource-dependencies</id>
      <phase>process-test-resources</phase>
      <goals>
        <goal>unpack-dependencies</goal>
      </goals>
      <configuration>
        <includeArtifactIds>my-artifact-id</includeArtifactIds>
        <includes>foobar.txt, loremipsum.xml</includes>
        <outputDirectory>${project.build.directory}/classes/xml-resources</outputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>

Have a look at the unpack-dependencies parameters for detailed explanation or further information.



来源:https://stackoverflow.com/questions/10532274/maven-extract-dependency-resources-before-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!