Gradle-eclipse seems to ignore any user defined logic in processResources and processTestResources tasks

gradle-eclipse seems to ignore any user defined logic (i.e. token filtering) in processResources and processTestResources tasks. In my particular case I have a project which filters property files during the execution of these tasks (a-la Maven resource filtering). When this project is executed in an IDE using gradle-eclipse the files copied over verbatim (i.e. with the tokens still in place). This causes all sorts of issues when reading these files as they contain the wrong values (i.e. the original tokens) at runtime.

Fortunately this works perfectly well when using Gradle straight from a shell, it’s just in the IDE (I’m using STS 3.2.0.M1) that tokens do not get replaced.

I attach a link to a sample project which demonstrates the issue:

http://dl.dropbox.com/u/123005133/gradle-resources-processing-issue.zip

Running ./gradlew clean build from a shell should yield a successful build in which the project’s single test, in PropertySlurperTest, will pass. However if this same project is imported as a Gradle project in to STS/ Eclipse then running the test in PropertySlurperTest will fail with the following message:

Assertion failed:

assert expectedPropertyValue == propertySlurper.getProperty("myProperty")
       |
                   |
|
             |
       "@expectedTestResult@"|
|
             "@myProperty@"
                             |
com.eddgrant.PropertyReader@687bc899
                             false

From what I can tell the filtering code that I have written in the build.gradle is not being executed when the processResources and processTestResources tasks are invoked in the IDE. I’m guessing however that the tasks are being invoked as the property files both in src/main/resources and src/test/resources are being copied over to the bin directory.

Would be most grateful if anyone knows why this is happening. Particularly for any steer as to whether I’m doing something wrong or whether this is actually a bug in gradle-eclipse?

If you need any further info to understand the problem please don’t hesitate to ask.

Many thanks.

Are you referring to building in Eclipse, or executing a Gradle build from Eclipse? The former doesn’t use Gradle (although it might in the future), and therefore doesn’t know about your customizations.

Hi Peter,

Thanks for your reply. I think I’m referring to building in Eclipse but I must admit I’m not entirely sure what the distinction between the two is? In the IDE I’m loading the project using “File | Import | Gradle | Gradle Project”. I’m then running the test class by right clicking the test method and selecting “Run As | JUnit Test”. I had simply presumed that Gradle would then be responsible for all the building of the project.

When I do this with Maven projects using M2E the project build which occurs in the IDE prior to the test being executed performs whatever filtering I have set up in the pom.xml. I had presumed that because I have installed gradle-eclipse and have imported a Gradle project that the IDE would use Gradle to build (compile, processResources etc) the project prior to executing the test class. But from what you’re describing this isn’t actually using Gradle?

As an IDE user it is a bit counter-intuitive that Gradle doesn’t perform the build, despite having imported the project specifically as a Gradle project. Is there a way then that I can ensure that the project gets built using Gradle prior to me executing my test?

Many thanks.

But from what you’re describing this isn’t actually using Gradle?

No it isn’t. Gradle is only used if you select some Gradle tasks to be executed (say ‘test’).

As an IDE user it is a bit counter-intuitive that Gradle doesn’t perform the build

I guess it depends on your background. It’s certainly our vision that Gradle will one day be responsible for the IDE build as well. In NetBeans, it already is.

Thanks again, given that is the current situation do you know of any way of running an individual test class through Gradle but within the IDE? I have tried selecting a test class and then selecting “Run As | Gradle Build” and selecting the test task but this (as I’d kind of anticipated) runs all the project’s test classes rather than the one I have selected.

I know this probably sounds like a really trivial thing but it’s a bit of a productivity killer not being able to run tests individually through the IDE as our project unfortunately takes a long time to run all tests using the test task.

Also, are there any anticipated timelines as to when Gradle might become responsible for the IDE build? Or is this something which is currently a long way off still? (Am just thinking about whether it’s worth switching back to using NetBeans…)

Cheers.

it’s a bit of a productivity killer not being able to run tests individually through the IDE

I’d recommend to set up the Eclipse project in such a way that you can do the bulk of the work (compile, debug, test) in the IDE. Anyway, this would make for a good feature request for the Eclipse plugin.

Also, are there any anticipated timelines as to when Gradle might become responsible for the IDE builds?

I don’t have any information on that. The Eclipse plugin is led by the SpringSource Tool Suite (STS) team, and I encourage you to get in contact with them via the STS forum and/or issue tracker.

I know this probably sounds like a really trivial thing but it’s a bit of a productivity killer not being able to run tests individually through the IDE

Why not running the specific test in the IDE via IDE? Eclipse is pretty good at running tests (visual output, stats, run current test etc.).

Hi Szczepan, thanks for commenting. I’m not sure I understand what you mean though. I am trying to run specific tests in the IDE, that’s exactly what I want to be able to do for all the reasons you mention. It’s just that I can’t because when the project is built in the IDE it doesn’t get built by Gradle (as per Peter’s comments above) and so in the case of the example project I provided (and many others with custom build logic in a build.gradle file) the project won’t be built correctly to satisfy the correct running of the tests.

Hey Edd,

I think Gradle should have better support for this use case out of the box. I’ll raise a ticket for it.

In meantime here’re a couple of options you have:

  1. If you don’t use STS, you can manipulate the content of the .classpath file using Gradle IDE tasks hooks:

{code} eclipse.classpath {

//add the post-filtered resources directory to the classpath

classFolders += sourceSets.main.output.resourcesDir

//remove the directory from sources

file.whenMerged { classpath ->

classpath.entries.removeAll { it.kind == ‘src’ && it.path == ‘src/main/resources’ }

} } {code}

  1. Rearrange the directories a bit. For example, put the pre-filtered resources outside of src/main/resources (e.g. instead make them generated into this folder).

  2. Keep a sample of post-filtered resource in the src/test/resources

  3. Rework the tests a bit: Isolate the tests that require the filtered resources. Let them work with sample data.

Hope that helps. Thanks for your efforts on trying to figure out this problem!

No worries - thanks for the suggestions, will have a think about how we could use them.

Was there any update on this issue? It seems like a really useful feature to have.

I have my tokens which are setup so I can deploy to dev, test and production environments. However, when I use the standard Eclipse build the tokens are not replaced and I am not able to successfully deploy my web application using the incremental Eclipse build.