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.

UPDATE 2018-09-18

It seems there is much better and easier way now: ResourceFilter

Example on that page exactly fits, just replace “node_modules” by “build”, so it looks like:

apply plugin: 'java'
apply plugin: 'eclipse'

eclipse {
    project {
        resourceFilter {
            appliesTo = 'FOLDERS'
            type = 'EXCLUDE_ALL'
            matcher {
                id = 'org.eclipse.ui.ide.multiFilter'
                arguments = '1.0-name-matches-false-false-build'
            }
        }
    }
}

OUTDATED VERSION

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.

Tags:  Gradle  Java  Eclipse 
Last blog articles:
Mým fuckupům
Ubuntu: Login loop
Leaving LinkedIn
LinkedIn: Odcházení
git gui: Add pull and stash commands

Tags:
Java Ubuntu česky Gradle personal Software-architecture DIY children React Eclipse DisplayLink AI Spring JavaScript AspectJ neuron SSH LXC JavaFX Immutables Gnome3 GIT FatJar Edison technologies startup science procrastination pokusy podnikání linux lambda kvas ellipsis destilace chemie alkohol VisualVM Upstart Tomcat Selenium REST PrimeFaces Log4j Jooq Jackson JSF Debug DI CSS

Last tweets: