Be able to easily customize the eclipse-wtp facet version

Hi.

I just gave a training about Java web development, using eclipse as an IDE, servlet 3.0, and gradle to create the project.

I had a problem though: gradle generates a jst-web facet with version 2.4. This makes eclipse continually generate an unwanted web.xml deployment descriptor (no web.xml is necessary with servlet 3.0), and with the wrong webapp version of course (2.4 instead of 3.0). As a result, the application isn’t functional anymore until the facet version is manually edited in the eclipse configuration file. And if the project is regenerated (because a dependency is added, for example), the configuration is lost.

I managed to customize the version with the following code:

eclipse {
  wtp {
    facet {
      file {
        whenMerged { wtpFacet ->
          def installedJstFacet = wtpFacet.facets.find { facet ->
            facet.name == 'jst.web' && facet.type == org.gradle.plugins.ide.eclipse.model.Facet.FacetType.installed
          }
          installedJstFacet.version = '3.0'
        }
      }
    }
  }
}

But I find it too complex to figure out, for something that should always be configured (the eclipse wizard for web projects asks which version the project should have).

I have a fix ready to be submitted as a pull request, which consists in adding a property webVersion in the DSL. The configuration would then become:

eclipse {
  wtp {
    facet {
      webVersion = '3.0'
    }
  }
}

Please tell me what you think about this. Should I submit a pull request? Is “webVersion” the appropriate name? Maybe “webAppVersion”?

Oh, and an additional question: should the default value of this version be changed to 3.0? 2.4 is really old now (2003). Changing it to 3.0 would provide a better default value, but would force existing builds relying on this default value to change their configuration is they migrate to the next version of gradle.

This would be a good change to make. Can you submit a pull request for this?

As far as the servlet API version goes, we should infer the default value from the compile dependencies. For example, if the servlet API version 3.0 is in the compile dependencies, use version 3.0, and if the servlet API version 2.6 is in the compile dependencies, use version 3.0.

I think

eclipse {
  wtp {
  facet {
    facet name: 'jst.web', version: '3.0'
    facet name: 'java', version: '1.7'
    facet name: 'wst.jsdt.web', version: '1.0'
  }
 }
}

already does that.