How to convert Java Gradle project to Dynamic Web Project?

I follow this article

https://www.linkedin.com/pulse/building-jax-rs-project-eclipse-gradle-neeraj-malhotra

How to create a JAX-RS project in Eclipse using Gradle

I use

Eclipse Java EE IDE for Web Developers.

Version: Oxygen.2 Release (4.7.2)
Build id: 20171218-0600

My lead time

WildFly Full 11.0.0.Final (WildFly Core 3.0.8.Final)

my gradle build file

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" 
}

I can select the required faces and set the target runtime, etc.

The boundaries that I choose

cdi 2.0
dynamic web module 3.1
java 1.8
jax-rs 2.1

As soon as I click "Apply and Close", the project does not report problems with the construction.

Currently, I do not like that the project has two WEB-INF files, one is at the project level, the other is in the WebContent folder, where I would expect this.

There is also a web.xml file, although I specifically did not choose to create web.xml.

, gradle, gradle.build gradle > refresh gradle.

,

cdi 2.0
jax-rs 2.1

- 2.4 3.1

MARKERS

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.

- , ?

gradle.build?

UPDATE

, Gradle

org.gradle.plugins.ide.eclipse.EclipseWtpPlugin:-

project.getPlugins().withType(WarPlugin.class, new Action<WarPlugin>() {
                    @Override
                    public void execute(WarPlugin warPlugin) {
                        ((IConventionAware) task.getFacet()).getConventionMapping().map("facets", new Callable<List<Facet>>() {
                            @Override
                            public List<Facet> 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()))
                                );
                            }
                        });
                    }

                });

jst.web org.eclipse.wst.common.project.facet.core.xml

<?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="jst.web" version="3.1"/>
</faceted-project>

can not gradle . - ?

buildship ...   http://download.eclipse.org/buildship/updates/e47/releases/2.x/2.2.1.v20180125-1441

gradle.build, - -.

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

, jst.web

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' && 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" 
}

eclipse

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.

, eclipse, , gradle, .

+4
1

, , : -

HACK gradle : -

apply plugin: 'war'
apply plugin: 'eclipse-wtp'

eclipse {
    project {
            buildCommands.clear();
            buildCommand 'org.eclipse.jdt.core.javabuilder'
            buildCommand 'org.eclipse.wst.common.project.facet.core.builder'
            buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
            buildCommand 'org.jboss.tools.jst.web.kb.kbbuilder'
            buildCommand 'org.jboss.tools.cdi.core.cdibuilder'
            buildCommand 'org.eclipse.wst.validation.validationbuilder'
   }
  wtp {
    facet {
      file {
            facet name: 'jst.web', version: '3.1'
            def oldJstWebFacet = facets.findAll {
                it.name == 'jst.web' && 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" 
}

" " ????????

+1

Source: https://habr.com/ru/post/1693740/


All Articles