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


(awarrenlove) #1

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.
gradle.plugins.ide.eclipse.model.EclipseWtp_Decorated.

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’.


(Peter Niederwieser) #2

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


(awarrenlove) #3

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?


(togin) #4

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.


(togin) #5

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.


(togin) #6

I see this is essentially a duplicate of http://forums.gradle.org/gradle/topics/wtp_elipse_requires_ear_or_war_i_need_wtp_to_build_ejb_modules_but_i_dont_want_an_ear_artifact which generated http://issues.gradle.org/browse/GRADLE-2221, so I do not need to do this.

I will investigate the solutions you offered in http://forums.gradle.org/gradle/topics/wtp_elipse_requires_ear_or_war_i_need_wtp_to_build_ejb_modules_but_i_dont_want_an_ear_artifact#reply_8558596

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


(togin) #7

Is this a duplicate issue? http://issues.gradle.org/browse/GRADLE-2186


(togin) #8

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.