How to override resources in test classpath like maven


(Corneil du Plessis) #1

When using Maven I can override a resource file by providing a file with the same name in the src/test/resources The files from test/resources will apppear in the classpath before the src/main/resources.

How can I achieve the same in Gradle? Can you change the default in Gradle so that it matches Maven? Also then ensure that the Eclipse plugin sees test resources and source before the main resources and source.


(Radim Kubacki) #2

I tried to reproduce this and it worked properly for me. Do you see this problem when running your test with Gradle or when you use your Eclipse project imported from Gradle? You can run Gradle with --debug and you will see the application classpath for your test runner - I see build/classes/test, buld/resources/test, build/classes/main, build/resources/main followed by dependencies.


(Corneil du Plessis) #3

The classpath order is incorrect in eclipse but it is correct running ‘gradle build’ .


(Radim Kubacki) #4

When I imported my test project into Eclipse I was warned that my shadowing resource was not copied into output folder (the one from main source set is already there). This is a good hint to help us find a solution. My idea is to tweak project settings and let the test classes and resources build their output into a different folder than the default ‘bin’. Then the JUnit launch configuration can create a classpath with both resources in correct order. It worked for me though I am not sure if there is any guarantee how it will be ordered. My guess is that output folders for src classpath entries are added first then project output folder is added and libraries/containers (dependencies) are last so you should be OK.

This customization of output folders can be added into your build script to make it a persistent setting - http://www.gradle.org/docs/current/userguide/eclipse_plugin.html