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

**URL:** <https://discuss.gradle.org/t/how-can-i-generate-a-multi-project-ear-and-a-deployable-eclipse-project/4179>\
**Category:** Old Forum Archive\
**Created:** [November 28, 2014, 7:18pm UTC](https://discuss.gradle.org/t/how-can-i-generate-a-multi-project-ear-and-a-deployable-eclipse-project/4179 "2014-11-28T19:18:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Augusto\_Cesar\_Dias](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/augusto_cesar_dias/32/278_2.png) [@Augusto\_Cesar\_Dias](https://discuss.gradle.org/u/Augusto_Cesar_Dias)\
**Post date:** [November 28, 2014, 7:18pm UTC](https://discuss.gradle.org/t/how-can-i-generate-a-multi-project-ear-and-a-deployable-eclipse-project/4179/1 "2014-11-28T19:18:00Z")

</div>

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:

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

```

And here’s my gradle file:

```gradle
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:

```gradle
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

---

<div class="post-metadata">

**Author:** ![Augusto\_Cesar\_Dias](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/augusto_cesar_dias/32/278_2.png) [@Augusto\_Cesar\_Dias](https://discuss.gradle.org/u/Augusto_Cesar_Dias)\
**Post date:** [November 28, 2014, 7:51pm UTC](https://discuss.gradle.org/t/how-can-i-generate-a-multi-project-ear-and-a-deployable-eclipse-project/4179/2 "2014-11-28T19:51:00Z")

</div>

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/](http://www.sinking.in/blog/provided-scope-in-gradle/)). Here’s what I have to do:

```gradle
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.
