1

I have a test resource that lives in resources/src/test/dir/sample.json, and it needs to move to /tmp/data/sample.json before unit tests can run. I want to use Maven to automate moving this file, without interfering with other test resources that need to move to target. The reason for this is that in production this file comes from outside the jar.

Looking at Maven's resource:testResources goal here and also the plugin. I'm not sure where to specify the outputDirectory, especially without interfering with anything else.

Will post more as I research, but I'm particularly afraid there's going to be several ways to do this and it's not going to be obvious which is the most conventional.

djechlin
  • 59,258
  • 35
  • 162
  • 290

1 Answers1

1

Assuming you are packaging jar, you would have resources:testResources in your process-test-resources life cycle. You would need the default execution which copies test resources as usual and the extra execution to copy the specific resource to specific output directory.

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>resources</artifactId>
        <version>1.0</version>
        <executions>
          <execution>
            <id>execution1</id>
            <phase>process-test-resources</phase>
            <goals>
              <goal>testResources</goal>
            </goals>
          </execution>
          <execution>
            <id>execution2</id>
            <phase>process-test-resources</phase>
            <configuration>
              <outputDirectory>
                 ...
              </outputDirectory>
              <resources>
                 ...
              </resources>
            </configuration>
            <goals>
              <goal>testResources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

See also

Kelvin Ng
  • 174
  • 1
  • 12