Gradle + Eclipse plugin: Remove build folder from Eclipse project

By default Eclipse plugin does not add /build folder into ignored resources and that may cause /build folder to be validated. Then many warnings will appear in Markers tab of Eclipse. Beside that it may be performance problem.

I found almost suitable solution here: https://discuss.gradle.org/t/eclipse-pluging-adding-resource-filters/5408 Unfortunately it adds new filter into configuration during each ‘gradle eclipse’. Here is my fix for that situation:


eclipse.project.file.withXml { xmlProvider ->
  Node project = xmlProvider.asNode()
  Node node = project

  if (node.filteredResources.isEmpty()) {
    node = node.appendNode('filteredResources')
  } else {
    node = node.filteredResources[0]
  }

  if (!node.filter.any {it.id[0].value()[0]=='1447321705713'}) {
    Node filter = node.appendNode('filter')

    filter.appendNode('id', '1447321705713')
    filter.appendNode('name', '')
    filter.appendNode('type', 10)
    Node matcher = filter.appendNode('matcher')
    matcher.appendNode('id', 'org.eclipse.ui.ide.multiFilter')
    matcher.appendNode('arguments', '1.0-name-matches-false-false-build')
  }
}

So filter node is added only in case it does not already exists.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s