title: How to convert Java Gradle project to Dynamic Web Project?
body: <p>I am following this article </p>
  
  <p><a href="https://www.linkedin.com/pulse/building-jax-rs-project-eclipse-gradle-neeraj-malhotra" rel="nofollow noreferrer">https://www.linkedin.com/pulse/building-jax-rs-project-eclipse-gradle-neeraj-malhotra</a></p>
  
  <p>On how to build a JAX-RS project in Eclipse with Gradle</p>
  
  <p>I am using</p>
  
  <pre><code>Eclipse Java EE IDE for Web Developers.
  
  Version: Oxygen.2 Release (4.7.2)
  Build id: 20171218-0600
  </code></pre>
  
  <p>My target runtime is </p>
  
  <pre><code>WildFly Full 11.0.0.Final (WildFly Core 3.0.8.Final)
  </code></pre>
  
  <p>my gradle build file</p>
  
  <pre><code>apply plugin: 'war'
  apply plugin: 'eclipse-wtp'
  
  sourceCompatibility = 1.8
  
  repositories {
   mavenCentral()
  }
  
  
  dependencies {
   compile "javax.ws.rs:javax.ws.rs-api:2.0.1"
   providedCompile "javax.servlet:javax.servlet-api:3.1.0" 
  }
  </code></pre>
  
  <p>I can select the required Facets and set target runtimes etc fine.</p>
  
  <p>The Facets I select are</p>
  
  <pre><code>cdi 2.0
  dynamic web module 3.1
  java 1.8
  jax-rs 2.1
  </code></pre>
  
  <p>Once I have click on Apply &amp; Close the project has no build issues reported.</p>
  
  <p>What I don't like at this point is that the project has two WEB-INF files
  one is at the project level, the other is within the WebContent folder where I would expect it.</p>
  
  <p>There is also a web.xml file even though I specifically didn't select to have a web.xml generated.</p>
  
  <p>The real issues start when I refresh my gradle build by right clicking on the gradle.build file and selecting gradle > refresh gradle project.</p>
  
  <p>When the refresh is complete the following facets have been deselected</p>
  
  <pre><code>cdi 2.0
  jax-rs 2.1
  </code></pre>
  
  <p>and my Dynamic Web Module has been downgraded to 2.4 from 3.1</p>
  
  <p>In addition to this I have the following two MARKERS</p>
  
  <pre><code>CDI Core Validator cannot run on project gradle_jax_rs because Validation Builder precedes CDI (Contexts and Dependency Injection) Builder.
  
  EL Validator cannot run on project gradle_jax_rs because Validation Builder precedes JBoss Knowledge Base Builder.
  </code></pre>
  
  <p>How can I configure my Dynamic Web Project so that it keeps my desired Facets at the level?</p>
  
  <p>What is my gradle.build missing?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>So I've tracked down the culprit in Gradle</p>
  
  <pre><code>org.gradle.plugins.ide.eclipse.EclipseWtpPlugin:-
  
  project.getPlugins().withType(WarPlugin.class, new Action&lt;WarPlugin&gt;() {
                      @Override
                      public void execute(WarPlugin warPlugin) {
                          ((IConventionAware) task.getFacet()).getConventionMapping().map("facets", new Callable&lt;List&lt;Facet&gt;&gt;() {
                              @Override
                              public List&lt;Facet&gt; call() throws Exception {
                                  return Lists.newArrayList(
                                      new Facet(Facet.FacetType.fixed, "jst.java", null),
                                      new Facet(Facet.FacetType.fixed, "jst.web", null),
                                      new Facet(Facet.FacetType.installed, "jst.web", "2.4"),
                                      new Facet(Facet.FacetType.installed, "jst.java", toJavaFacetVersion(project.getConvention().getPlugin(JavaPluginConvention.class).getSourceCompatibility()))
                                  );
                              }
                          });
                      }
  
                  });
  </code></pre>
  
  <p>This results in duplicate <code>jst.web</code> entries in <code>org.eclipse.wst.common.project.facet.core.xml</code></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;faceted-project&gt;
      &lt;fixed facet="jst.java"/&gt;
      &lt;fixed facet="jst.web"/&gt;
      &lt;installed facet="jst.web" version="2.4"/&gt;
      &lt;installed facet="jst.java" version="1.8"/&gt;
      &lt;installed facet="jst.web" version="3.1"/&gt;
  &lt;/faceted-project&gt;
  </code></pre>
  
  <p>Why cant Gradle work correctly. Whats hard about building a Dynamic Web Project with the selected facets?</p>
  
  <p>I have upgraded <code>buildship</code> to...
      <a href="http://download.eclipse.org/buildship/updates/e47/releases/2.x/2.2.1.v20180125-1441" rel="nofollow noreferrer">http://download.eclipse.org/buildship/updates/e47/releases/2.x/2.2.1.v20180125-1441</a></p>
  
  <p>even with this added to my gradle.build it still cannot build the required dynamic web project correctly</p>
  
  <pre><code>eclipse {
              wtp {
                  facet {
                      facet name: 'java', version: '1.8'
                      facet name: 'jst.web', version: '3.1'
                      facet name: 'wst.jsdt.web', version: '1.0'
                  }
              } 
          } 
  </code></pre>
  
  <p>Found that this clunky hack fixes the duplicate jst.web versions</p>
  
  <pre><code>apply plugin: 'war'
  apply plugin: 'eclipse-wtp'
  
  eclipse.wtp.facet {
      file {
              facet name: 'jst.web', version: '3.1'
              def oldJstWebFacet = facets.findAll {
                  it.name == 'jst.web' &amp;&amp; it.version == '2.4'
              }
              facets.removeAll(oldJstWebFacet)
              facet name: 'java', version: '1.8'
              facet name: 'jst.cdi', version: '2.0'
              facet name: 'jst.jaxrs', version: '2.1'
              facet name: 'wst.jsdt.web', version: '1.0'              
          }
  }
  
  repositories {
   mavenCentral()
  }
  
  dependencies {
   compile "javax.ws.rs:javax.ws.rs-api:2.0.1"
   providedCompile "javax.servlet:javax.servlet-api:3.1.0" 
  }
  </code></pre>
  
  <p>however now I have the following two eclipse error markers</p>
  
  <pre><code>CDI Core Validator cannot run on project Attempt0002 because Validation Builder precedes CDI (Contexts and Dependency Injection) Builder.
  
  EL Validator cannot run on project Attempt0002 because Validation Builder precedes JBoss Knowledge Base Builder.
  </code></pre>
  
  <p>I can resolve this issue by amending the builder order within eclipse, however as soon as I build my project with Gradle the issue reappears.</p>