Eclipse-wtp facet creates duplicates

Hello,

in a multiproject build, I want to enforce a certain facet configuration on all subprojects with plugin 'war’
So did this:

subprojects {
	def configureFacets = {
	// TODO configure facets according to ear/war type
		eclipse {
			wtp {
        		facet {
            		facet name: 'java', version: '1.8'
            		facet name: 'jst.web', version: '3.0'
            		facet name: 'com.ibm.websphere.coexistence.web', version: '8.5'
				facet name: 'com.ibm.websphere.extended.web', version: '8.5'
            		facet name: 'wst.jsdt.web', version: '1.0'
        		}
        	} 
		} 
	}  
	pluginManager.withPlugin('eclipse-wtp',configureFacets)
}

The problem is that the resulting facet configuration is different:

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
	<fixed facet="jst.java"/>
	<fixed facet="jst.web"/>
	<installed facet="jst.web" version="2.4"/>
	<installed facet="jst.java" version="1.8"/>
	<installed facet="java" version="1.8"/>
	<installed facet="jst.web" version="3.0"/>
	<installed facet="com.ibm.websphere.coexistence.web" version="8.5"/>
	<installed facet="com.ibm.websphere.extended.web" version="8.5"/>
	<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>

I tried to delete the entire .settings directory and it gets recreated with ‘org.eclipse.wst.common.project.facet.core.xml’ containing the above.
I suspect gradle doing that as I can see from this code:

How can I overwrite?

Update:
I came so far to be able to remove the line added by the eclipse using the following, but I miss the right syntax to add a facet. Any idea?

		eclipse.wtp.facet {
      		file {
        		whenMerged { wtpFacet ->
        			wtpFacet.facets.removeAll { entry -> entry.name == 'jst.web'}
        			wtpFacet.facets.add { entry -> ????}
        		}
//        		facet name: 'java', version: '1.8'
//				facet name: 'jst.web', version: '3.0'
//				facet name: 'com.ibm.websphere.coexistence.web', version: '8.5'
//				facet name: 'com.ibm.websphere.extended.web', version: '8.5'
//				facet name: 'wst.jsdt.web', version: '1.0'        		
  			}
		}

Hi, I have the same problem.
Have you found a solution?

Unfortunately not. At the end I dropped the idea of manipulating facets. It was not critical

Hi Andreas,

I found a solution that works for me just in case you want to give it a try. What I did is add the facets that I need and then remove any unwanted entries. In this case I removed jst.java since it is duplicated with our java entry and jst.web that is not version 3.0. Hope this helps.

eclipse.wtp.facet {
    facet name: 'java', version: '1.8' 
    facet name: 'jst.web', version: '3.0' 
    facet name: 'com.ibm.websphere.coexistence.web', version: '8.5' 
    facet name: 'com.ibm.websphere.extended.web', version: '8.5' 
    facet name: 'wst.jsdt.web', version: '1.0'

    file {
        whenMerged { 
            wtpFacet -> wtpFacet.facets.removeAll { 
                entry -> entry.name == 'jst.web' && entry.version != '3.0' || 
                entry.name == 'jst.java' 
            }
        }
    }
}

in the whenMerged block you get a org.gradle.plugins.ide.eclipse.model.WtpFacet to work with. That beeing said, you can only add org.gradle.plugins.ide.eclipse.model.Facet objects to the list of facets wich can be created with the constuctor public Facet(String name, String version).

If you just want to adjust the version you can also set it:

eclipse.wtp.facet.file.whenMerged {
	wtpFacet ->	wtpFacet.facets.forEach { entry -> 
		if(entry.name == 'jst.ear' && entry.version != null) {
		 	entry.version = '6.0'
		}
	}
}

just be sure to only set the version for “installed” facets and not the “fixed” entries (that why i check if a version is already set).

Hope this helps someone, who’s looking for this issue in 2019, as there’s still no convinient way to configure facets and their versions today :frowning: