Package Jar into EAR in same project

Hi

I would like to create a project which packages a Jar of the current project and then adds this Jar to the EAR. I know i can split it in 2 projects, but thats not my desired project setup. I have many specific subprojects and these subprojects result in different EARs.

apply plugin: 'java'
apply plugin: 'ear'
apply plugin: 'eclipse'
  group = "myorg"
version = "0.6"
  def projectDirPath = project.projectDir.canonicalPath
  repositories {
 mavenCentral()
 mavenLocal()
 maven {
        url "http://repository.jboss.org/nexus/content/groups/public-jboss/"
    }
}
  configurations {
 customJar
}
  task packageJar(dependsOn:classes, type: Jar) {
    archiveName="customJar.${extension}"
    from sourceSets.main.output
}
  artifacts {
 customJar packageJar
}
  dependencies {
        // Jar dependencies
    compile project(':mcommerce')
    compile 'org.jboss.spec:jboss-javaee-6.0:2.0.0.Final'
    compile 'org.jboss.logging:jboss-logging:3.0.0.GA'
          // EAR dependencies
    deploy files("${buildDir}/lib/customJar.jar")
    deploy project(':mcommerce')
    deploy project(path: ':mcommerce-admin', configuration: 'archives')
    deploy project(':login')
          earlib project(':xml')
    earlib 'edu.ucar:netcdf:4.2.20'
    earlib 'commons-fileupload:commons-fileupload:1.2.2'
    earlib 'commons-io:commons-io:2.0.1'
}
  ear.dependsOn packageJar
  ear {
  excludes += [
    "**/*.class"
  ]
  includeEmptyDirs = false
  archiveName="archive.${extension}"
}

With the task packageJar I am able to create the desired jar. Now I would like to add the Jar to the EAR, but i don’t know how. The first line of the EAR dependencies is my attempt, but it does not work.

The excludes filter the compiled classes of the EAR.

Does somebody have an idea how to solve?

Ok seems to work with this, was just a typo.

// EAR dependencies
deploy files("${buildDir}/libs/customJar.jar")

However I have to manually exclude the class files (the empty class directories still appear in EAR, which is not ideal). Maybe I will find a better solution.