Help get this topic noticed by sharing it on Twitter, Facebook, or email.

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/gra...

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.
1 person has
this question
+1
Reply
  • 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.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • 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.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • > 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.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited

  • 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.
    • view 2 more comments
    • Szczepan Faber (Gradleware engineer) January 28, 2013 12:24
      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}

      2. 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).

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

      4. 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.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • > 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.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned sad, anxious, confused, frustrated happy, confident, thankful, excited