Uploading multiple ear files from file system dir


I have a multimodule project that someone else have done. It generates multiple .ear files through a external tool (product provided tool) in a filesystem dir. I want to upload these .ear files to Nexus maven repository in through init script , but if i declare more than one artifacts -> archives of type: ‘ear’ it just uploads one. I’ve tried changing the type to ‘EAR’ and ‘jar’ and it works.

Is this the way it behaves , there is something that I’m missing or I’m doing something wrong?.

I’ve pasted the code I’m using in the init script below. Also on pastebin http://pastebin.com/VjhnFca5

  def dirEars_dir = "/ears"
  def earArtifactsList = []
  artifacts {
   new File(dirEars).eachFileMatch(~/.*.ear/) {fileEar ->
    archives file: file(fileEar.getAbsolutePath()), name: fileEar.getName().replaceAll(".ear",""), type: 'ear'
    rootProject.group = "com.myproject"
  rootProject.version = "0.1-SNAPSHOT"
   repositories {
    mavenDeployer {
     uniqueVersion = false
     name = 'earsUpload'
     repository(id: "ears",url: "${mavenRepositoryReleasesUrl}")
     snapshotRepository(id: "ears-snapshots",url: "${mavenRepositorySnapshotsUrl}")
       earArtifactsList.each { earName ->
      addFilter(earName) {artifact, file ->
       artifact.name == earName
      pom(earName).artifactId = earName
      pom(earName).groupId = "${rootProject.group}"
      pom(earName).version = "${rootProject.version}"

Thanks in advance,


I had this problem once and figured it is due to the DefaultArtifactPublicationSet class. Not sure why it is implemented that way, but you could probably try to use a different configuration to avoid this behavior, or maybe set the artifact type after it is added to the ‘archives’ configuration.

Hi Detelin,

Thanks a lot for the reply. Once I’ve seen why this was happening on the DefaultArtifactPublicationSet class, I’ve managed to declare the artifacts with another type and change it after it is added to the archives.

configurations.archives.artifacts.each{ artifact ->
   artifact.type = 'ear'