Could not find method facet() in eclipse-wtp plugin

I have added the eclipse-wtp plugin to a Java project, and I want to use that to add Java and Utility facets to my project. However, when I added the following code:

eclipse {
 wtp {
  facet {
   facet name: 'java', version: '1.5'

I get the following error:

> Could not find method facet() for arguments [{name=java, version=1.5}] on org.

I also tried

eclipse.wtp.facet {
 facet name: 'java', version: '1.5'

but that gave me an error that it couldn’t find method “facet()” on the root project, so it appears it isn’t getting the right object in either case. Does anyone know what I’m doing wrong? For reference, the other plugins I have applied are ‘java’ and ‘maven’.

Facet support is only available when you apply the ‘war’ or ‘ear’ plugin.

Out of curiosity, what is the reasoning for that? Facets can be applied to non-War/Ear projects, so why wouldn’t there be a need to generate them for those projects?

Bump. Is there an answer to this?

I am guessing I could just add the war plugin onto these projects, but this seems silly to do.

If it is helpful I can write up a JIRA improvement issue for this, but I don’t want to proceed if there is some technical reasoning why this is the case.

I see this is essentially a duplicate of which generated, so I do not need to do this.

I will investigate the solutions you offered in

Preferably I would like to avoid applying the war or ear plugin.

Is this a duplicate issue?

For those stumbling upon this issue, the easiest way to handle this is to apply the following snippets to your project:

apply plugin: ‘ear’

ear.onlyIf { false }

After that, you can apply whatever facets you want and they’ll get initialized.

Using the war plugin ends up telling eclipse-wtp to generate a lot of library metadata you probably don’t want, however the ear does no such thing.