1

I want to skip copying the test resources during build. I tried the following plugin configuration:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>testResources</goal>
                    </goals>
                    <phase>process-test-resources</phase>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Alas it's still copying the resources. I tried a couple of different phases (compile, test) but to no avail.

[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ Project---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 5635 resources

What do I have to do so this is skipped?

Martin
  • 852
  • 7
  • 20
  • First why are you trying to skip this? And furthermore why do you have so much resources ? – khmarbaise Dec 24 '19 at 08:57
  • I'm building an installer for my software. Part of it copies a couple of files (third party) into some location and executes third party installers. I test my code mostly with mocks but some without (some kind of integration test). I access my test resources not via ```getClass().getResource(resoruceName)``` but directly access them via ```Path source = Paths.get("src", "test", "resources", "someResource")``` So there is no need to copy the test resources via maven. – Martin Dec 24 '19 at 09:04
  • So why have you so many resources in test area? Usually you should have only them which you need for your tests...the others should be in `src/main/resources` instead...and never access your resources via a path... – khmarbaise Dec 24 '19 at 09:14
  • As I said: My software executes third party installers and some of them are actually executed during test. Some of these installers are a bit more then just simple executables. I access the test resources via path because it's more flexible than ```getClass().getResoruces()```. I know the pro and cons of this approach and I have decided the pros outweigh the cons. But could we please focus on my question? ;) – Martin Dec 24 '19 at 09:20
  • So either you need the resources during your tests or you don't. If you need them then you can't skip the resource copying..otherwise you have to remove the resources from the location and there will be no copying ? What I don't understand why you execute installers during a test? That sounds more like integration tests than unit tests... – khmarbaise Dec 24 '19 at 09:23
  • Yes, some of the test are no strict unit tests. I have different test groups. Not all are executed all the time. Some are only executed on for instance jenkins. Therefore I don't what that all the test resources are always copied when a test is executed. They should only be copied when specific tests are executed. SoI handle copying of test resources by myself using ```@Before @After``` – Martin Dec 24 '19 at 09:30
  • While I'm not sure your approach is sensible, I guess the technical problem lies in the missing `` in your execution definition. I don't know the right id, but I guess it is something like `default`. – J Fabian Meier Dec 24 '19 at 09:52
  • 1
    You are right @JF Meier. The missing id tag was the issue. ```default-testResources``` solved the problem. Could you please create an answer and I happily accept it. Thank you. – Martin Dec 24 '19 at 09:57

1 Answers1

0

To specify what test resources are copied specify a testResources block in the pom.xml file:

    <testResources>
        <testResource>
            <directory>src/test/resources</directory>
            <excludes>
                <exclude>YOUR_FILES_HERE</exclude>
            </excludes>
        </testResource>
    </testResources>

This works in the same way the normal resources works.

Source:

https://maven.apache.org/plugins/maven-resources-plugin/usage.html