Gradle create Eclipse EAR project

I am migrating a legacy project from ant

to gradle

(to use its dependency management and build functionality) and eclipse

there is a problem before building the projects . The big problem today is that there are several sub-projects in the project, which are split into packages war

and jars for deployment into one ear

. This is done today ant

. To use gradle

, I have split projects eclipse

into separate projects jar

and war

. So I have the following structure:

ProjectRoot
-lib
-Project1.jar
-Project1.war
-Project2.jar
-Project3.war

      

And here is my gradle

file
:

apply plugin: 'ear'
def jboss_home = '/home/augusto/Development/servers/jboss6X' 
def deploy_name = 'default'

allprojects {
    repositories {
        mavenCentral()
    }
    apply plugin: 'eclipse'
    apply plugin: 'eclipse-wtp'
}

dependencies {
    deploy project(path: 'Project1.jar', configuration: 'archives')
    deploy project(path: 'Project1.war', configuration: 'archives')
    deploy project(path: 'Project2.jar', configuration: 'archives')
    deploy project(path: 'Project2.war', configuration: 'archives')
    earlib fileTree(dir: 'lib', include: '*.jar')
}

ear {
    libDirName = "lib"
    deploymentDescriptor {
        applicationName = "MyApp"
        initializeInOrder = true
        displayName = "MyApp"
        module("Project1.jar", "java")
        module("Project2.jar", "java")
        webModule("Project1.war", "/Project1")
        webModule("Project2.war", "/Project2")
    }
}

project('MyJarLib') {
    apply plugin: 'java'
    dependencies {
        compile files('../lib/ajar.jar')
        compile fileTree(dir: jboss_home + '/common/lib', include: '*.jar')
        compile fileTree(dir: jboss_home + '/client', include: '*.jar')
        compile fileTree(dir: jboss_home + '/lib', include: '*.jar')
        compile fileTree(dir: jboss_home + '/server/' + deploy_name + '/lib', include: '*.jar')
    }
}

project('Project1.jar') {
    apply plugin: 'java'
    dependencies {
        compile 'org.apache.poi:poi:3.2-FINAL', 'jdom:jdom:1.1'
        compile project(':MyJarLib.jar')
    }
}

project('Project1.war') {
    apply plugin: 'war'
}

project('Project2.jar') {
    apply plugin: 'java'
    dependencies {
        compile 'net.sf.jasperreports:jasperreports:3.7.0', 'jdom:jdom:1.1'
        compile project(':MyJarLib.jar')
    }
}

project('Project2.war') {
    apply plugin: 'war'
}

      

I added a plugin ear

in subprojects to deploy to server using eclipse

. If I only allow the jar, I cannot deploy to the server using eclipse (and I want to do this to use the hot deploy feature from jboss 6). Our team has a big performance issue to run this app due to ant

builds. It takes almost 15 minutes to test the feature because they can't use hot deploy ... Problem with eclipse

: Deploy doesn't generate one ear

. It deploys the packages separately, and the server is not deployed. Problem with construction gradle

: it generates the correct structure, but it creates files application.xml

inside each jar project (due to the ear plugin). I only use rootapplication.xml

... Can you help me solve both of these problems? Thank.

EDIT

I managed to get eclipse to deploy my project using the advice in the comments. In all java projects I put this config:

apply plugin: 'ear'
ear.onlyIf { false }
ear {
    //appDirName 'src/main/java'
    libDirName '../lib'
}

sourceSets {
    main {
    java {
        srcDir 'src/main/application'
    }
    }
}
eclipse.wtp.facet {
    facet name: 'jst.ejb', version: '3.1'
    facet name: 'java', version: '1.6'
}
eclipse.classpath.file{
    withXml {
    def nodes = it.asNode().children().findAll{it.@kind == 'lib'}
    nodes.each {
        if(it.attributes[0] == null)
            it.appendNode('attributes').appendNode('attribute', [name:'org.eclipse.jst.component.dependency', value: '../lib'])
        else
            it.attributes[0].attribute[0].@value = '../lib'
    }
    }
}

      

I installed the ear plugin so gradle builds a project ready to be deployed to eclipse. ear.onlyIf { false }

makes gradle not generate artifact in the ear structure. After that, I changed the eclipse settings to set the project edge to EJB and changed the classpath entries to deploy dependencies in the ear lib directory instead of the ear root. My problem is now building from gradle. When I callgradle ear

, it generates a lot of dependency errors due to the web container library not on the classpath ... So I have a lot of classnotfound exceptions. If I put all the classes as dependencies from my project, it messes up the eclipse classpath (and is deployed). The question is, is there a way to provide the provided dependency for java projects in gradle and is there an easy way to provide all of these jars from jboss instead of each one?

+3


source to share


1 answer


I managed to get all the work done. Using workarounds in my editing part of the question and some paragraphs of this article . Here's what I need to do:

configurations {
    provided
}

sourceSets {
    main {
    compileClasspath += configurations.provided
    compileClasspath += configurations.compile
    compileClasspath += configurations.runtime
    java {
        srcDir 'src/main/application'
    }
    }
}

      



It became possible to use this in dependencies of all my projects and it doesn't contradict the eclipse project.

0


source







All Articles