Maven:在测试之前提取依赖性资源

fly*_*lyx 6 maven-2 maven maven-dependency-plugin

我有一个多模块Maven项目.一个子项目托管XSL/XML资源文件.另一个项目托管需要在单元测试中使用这些文件的Java代码.

在依赖项的jar中,资源位于文件夹中xml-resources.

我找到了这个例子,并试图根据我的需要改变它:

<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>
Run Code Online (Sandbox Code Playgroud)

当我运行process-test-resources阶段时,这没有任何作用.我确定那里有一些错误 - 我没有看到我可以在哪里指定资源应该从中获取的依赖关系,并且<classifier>似乎没有实际指定应该从中复制资源的源.

我迷失在这里,有人可以告诉我该怎么做对吗?

FrV*_*aBe 8

尝试这样的事情

<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>
Run Code Online (Sandbox Code Playgroud)

有关详细说明或更多信息,请查看unpack-dependencies参数.

  • 在这种情况下,outputDirectory文件夹应该是../test-classes/ ..而不是../ classes/.... (2认同)