WAR project - upload archives - API jar


(David Harrigan) #1

Hi,

Gradle 1.6 Java 1.7u21

So, I have a WAR project, and two jar tasks, i.e.,

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'maven'
  task domainJar(type: Jar, dependsOn: classes) {
    includeEmptyDirs = false
    include("**/common/domain/**")
}
  task sourcesJar(type: Jar, dependsOn: classes) {
    includeEmptyDirs = false
    classifier = 'sources'
    from sourceSets.main.allJava
    include("**/common/domain/**")
}
  artifacts {
    archives sourcesJar
    archives domainJar
}

I’m having difficultly uploading using the mavenDeployer…firstly:

  1. I don’t want the WAR to be uploaded. It seems to want to do that. 2. I can’t seem to get the domainJar or sourcesJar to upload, i.e.,
What went wrong:
Execution failed for task ':uploadArchives'.
> Could not publish configuration 'archives'
   > A POM can not have multiple main artifacts. Already have MavenArtifact foo:war:war:null, trying to add MavenArtifact foo:jar:jar:null

I then tried this (also modifing the domainJar task and sourceJar task to have a baseName):

uploadArchives {
    repositories {
        mavenDeployer {
            snapshotRepository(url: "${repositoryUrl}/libs-snapshot-local")
            addFilter('domainJar') {artifact, file ->
                artifact.name == 'domain'
            }
            addFilter('sourcesJar') {artifact, file ->
                artifact.name == 'sources'
            }
            repository(url: "${repositoryUrl}/libs-releases-local")
        }
    }
}

But that just produces ugly jar names (like sources-0.1.0-SNAPSHOT-sources.jar). If I try to use the proper name in baseName, then I get the same error as above, in that the it says “Already have…”.

Anyone with suggestions on this one please? Thank you.