JoseK
JoseK

Reputation: 31371

Gradle - generating and installing multiple jar from single project

I'm able to build the jars I need - but using gradle install I get the error

A POM cannot have multiple artifacts with the same type and classifier. Alr eady have MavenArtifact a:jar:jar:null, trying to add MavenArtifact a:jar:jar:null.

As per the docs, setting a different baseName for each archive would resolve this but it doesnt.

I've tried Gradle 2.2.1 in case that matters.

Relevant build.gradle

task package1 (type: Jar) {
    baseName = "a1"
    include "**/packageA/**"
}

task package2 (type: Jar) {
    baseName "a2"
    include "**/packageB/**"
}

task package3 (type: Jar) {
    baseName "a3"
    include "**/packageC/**"
}
artifacts{
    archives package1,package2,package3

}

I dont want to set different classifier or type for Maven POMs to be different. Is that the only option?

Other references: http://forums.gradle.org/gradle/topics/how_to_publish_multiple_artifacts_w_sources_per_project

Upvotes: 1

Views: 2631

Answers (1)

JoseK
JoseK

Reputation: 31371

I got this working using gradle publish as per the method described at https://gradle.org/docs/current/userguide/publishing_maven.html

task package1 (type: Jar) {
    baseName "a1"
    version "0.1"
    from (sourceSets.main.output){
    include "com/packagea/**"
    }
}

task package2 (type: Jar) {
    baseName "a2"
    from (sourceSets.main.output){
    include "com/packageb/**"
    }
}

// We use the publishing task instead of gradle install to deploy the jar into the local MAVENREPO
publishing {
    publications {
        publisha1(MavenPublication) {
            groupId 'com.my'
            artifactId 'a1'
            version '0.1'
            artifact package1 
        }
        publishb1(MavenPublication) {
            groupId 'com.my'
            artifactId 'b1'
            version '0.1'
            artifact package2 
        }
}

Upvotes: 1

Related Questions