How can I generate a multi-project EAR and a deployable eclipse project?

I’m migrating a legacy project from ant to gradle (to use its dependency management and build features) and I’m facing a problem when generating the eclipse projects. The big problem today is because the project has some subprojects that are split into war and jar packages to deploy into a single ear. This is made by ant today. To use gradle I split the eclipse projects into separate jar and war projects. So I have the following structure:

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

And here’s 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'
}

After searching a lot on google I’ve come to do this to solve part of my problem: In all jar projects I’ve put this configuration:

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

This generates an eclipse project that can be deployable by its jboss plugin (this way I can use hot deploy in dev time). i just add the project to jboss, hit start and it works fine. But when I call gradle ear to generate a deployable ear for me, I get a lot of compilation errors. First one: the runtime dependencies I put in each project seems to be not working since I’m getting a lot of classnotfound exceptions. I have some libraries that are not in maven repositories, so I put them in the lib path from the root project and I use them like this - compile files(’…/lib/mylib.jar’) Second one: if I resolve the jars from jboss in compile of my jar project, it puts all of them in deploy from eclipse (and this mess my project in it). Is there some kind of providedCompile for java or ear plugins? Thank you

I’ve managed to make all work. Using the workarounds in my edit part of the question and some points of this article (http://www.sinking.in/blog/provided-scope-in-gradle/). Here’s what I have to do:

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

This made possible to use provided in the dependencies of all my projects and it does not mess with the eclipse project.