Maven POM generation and multiple archive artifacts doesn't work

Multiple artifacts generated per project and Maven POM generation issue. In an attempt to allow a jar/war/ear be generated within the same project, the current sticking point is that any attempt to publish to a maven repository results in an error because it currently assumes there is only one artifact as part of the archives configuration.

Suggestions on the best way to make this possible?

This is the way to accomplish publishing multiple artifacts:

http://gradle.org/current/docs/userguide/userguide_single.html#sub:multiple_artifacts_per_project

You may find it more convenient to filter based on the artifact.ext as opposed to artifact.name from the Gradle manual. I.e.

uploadArchives {
    repositories.mavenDeployer {
        repository(url: "file://localhost/tmp/myRepo/")
        addFilter('ear') {artifact, file ->
            artifact.ext == 'ear'
        }
        addFilter('war') {artifact, file ->
            artifact.ext == 'war'
        }
        pom('war').version = 'mySpecialMavenVersion'
    }
}

So… I’m reading this as “not a problem”, but a breaking change that would have to be identified for anyone using the war/ear plugins and trying to upload artifacts. I’d have to change the integration tests using filters like above, and all would work fine.

Thanks for the input. I’m sure there will be some other folks weighing in whether this is the desired path.

-Spencer

Hallo, I also have the same problem. I have some subprojects. For every subproject I want to upload an artifact file. That is no problem. But I also want to upload an jar artifact. For that I have following part :

artifacts {
  archives file('build/recordmanagement-repository-'+version+'.amp'), file('build/recordmanagement-defaultRepositoryPlugin-'+version+'.amp'),
     file('build/recordmanagement-share-'+version+'.amp'), file('build/recordmanagement-defaultSharePlugin-'+version+'.amp'), file('build/libs/recordmanagement-repository-'+version+'.jar')
 }

When I remove following part from above code:

file('build/recordmanagement-defaultSharePlugin-'+version+'.amp'), file('build/libs/recordmanagement-repository-'+version+'.jar')

it works. But when I add it, I get following error:

* Exception is:
     [exec] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':RecordManagement Repository:uploadArchives'.
...
Caused by: org.gradle.api.artifacts.PublishException: Could not publish configuration ':RecordManagement Repository:archives'.
..
Caused by: org.gradle.api.InvalidUserDataException: A POM can not have multiple main artifacts. Already have MavenArtifact recordmanagement-repository:war:war:null, trying to add MavenArtifact recordmanagement-repository:jar:jar:null

That is the important part of the build script:

allprojects {
 ext.groupId='com.westernacher.recordmanagement'
 ext.version='1.0.0-RELEASE'
    group='com.westernacher.recordmanagement'
    version='1.0.0-RELEASE'
    repositories {
      maven {
   credentials {
    username artifactoryRepoUsername
    password artifactoryRepoPassword
   }
   url 'http://xyz'
  }
      maven {
   credentials {
    username artifactoryRepoUsername
    password artifactoryRepoPassword
   }
   url 'http://xyz'
  }
 }
    apply plugin: 'java'
 apply plugin: 'war'
 apply plugin: 'maven'
       // enable generation of jar, for war files and puts them into war
 war {
  classpath = jar.outputs.files + configurations.runtime - configurations.providedRuntime
  classpath = projectDir.path + "/src/main/profiles/${rootProject.ext.profile}/"
 }
 jar {
       metaInf {
           from files('src/main/META-INF')
      }
      }
    [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
 compileJava.options.debugOptions.debugLevel = 'source,lines,vars'
    artifacts {
  archives file('build/recordmanagement-repository-'+version+'.amp'), file('build/recordmanagement-defaultRepositoryPlugin-'+version+'.amp'),
     file('build/recordmanagement-share-'+version+'.amp'), file('build/recordmanagement-defaultSharePlugin-'+version+'.amp'), file('build/libs/recordmanagement-repository-'+version+'.jar')
 }
 uploadArchives {
  repositories {
   mavenDeployer {
    repository(url: "http://xyz") {
              authentication(userName: artifactoryRepoUsername, password: artifactoryRepoPassword)
              addFilter('recordmanagement-repository') {artifact, file ->
                      artifact.name == 'recordmanagement-repository'
                 }
              MavenPom pomDefaultRepositoryPlugin = addFilter('recordmanagement-defaultRepositoryPlugin') {artifact, file ->
                     artifact.name == 'recordmanagement-defaultRepositoryPlugin'
                         }
     // fix project compile dependency (should not be needed starting from 1.0, see http://issues.gradle.org/browse/GRADLE-443)
     pomDefaultRepositoryPlugin.whenConfigured {pom ->
      pom.dependencies.find { dep -> dep.artifactId == 'RecordManagement Repository' }.artifactId = 'recordmanagement-repository'
     }
                     addFilter('recordmanagement-share') {artifact, file ->
                     artifact.name == 'recordmanagement-share'
                 }
              addFilter('recordmanagement-defaultSharePlugin') {artifact, file ->
                     artifact.name == 'recordmanagement-defaultSharePlugin'
                 }
                }
                snapshotRepository(url: 'http://xyz'){
                    authentication(userName: artifactoryRepoUsername, password: artifactoryRepoPassword)
                    addFilter('recordmanagement-repository') {artifact, file ->
                      artifact.name == 'recordmanagement-repository'
                 }
              MavenPom pomDefaultRepositoryPlugin = addFilter('recordmanagement-defaultRepositoryPlugin') {artifact, file ->
                     artifact.name == 'recordmanagement-defaultRepositoryPlugin'
                         }
     // fix project compile dependency (should not be needed starting from 1.0, see http://issues.gradle.org/browse/GRADLE-443)
     pomDefaultRepositoryPlugin.whenConfigured {pom ->
      pom.dependencies.find { dep -> dep.artifactId == 'RecordManagement Repository' }.artifactId = 'recordmanagement-repository'
     }
              addFilter('recordmanagement-share') {artifact, file ->
                     artifact.name == 'recordmanagement-share'
                 }
              addFilter('recordmanagement-defaultSharePlugin') {artifact, file ->
                     artifact.name == 'recordmanagement-defaultSharePlugin'
                 }
                }
   }
  }
 }
   }

Where is the problem? What do I have to change?

Thanks for a reply!

Shalom Amin Zamani