Maven publication 'maven' cannot include multiple components

Viewed 2603

When I am building multi-project with multibranch using this command with Gradle 6.0:

./gradlew :soa-report-consumer-multi_master:soa-report-consumer-api:build publishMavenPublicationToMavenRepository -x test -PpubRepoUrl=https://nexus.balabala.com/repository/maven-releases/ -PmultibranchProjDir=soa-report-consumer-multi_master

shows this eror:

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/dabaidabai/.jenkins/workspace/t-consumer-multi_feature_happygo/build.gradle' line: 35

* What went wrong:
A problem occurred evaluating project ':t-consumer-multi_feature_happygo'.
> Maven publication 'maven' cannot include multiple components

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

this is my build.gradle config in sub project:

project(":$consumerMultibranchProjDir:soa-report-consumer-api") {
    jar {
        enabled = true
    }

    bootJar {
        enabled = false
    }
    archivesBaseName = "soa-report-consumer-api"
    version = "1.0.0-RELEASE"
    jar {
        enabled = true
    }

    dependencies {
        api("com.sportswin.soa:soa-misc-biz:1.0.0-RELEASE")
        api project(":soa-wallet:soa-wallet-api")
    }

    publishing {
        publications {
            maven(MavenPublication) {
                groupId 'com.sportswin.soa'
                artifactId 'soa-report-consumer-api'
                version '1.0.0-RELEASE'
                from components.java

                artifact sourceJar {
                    classifier "sources"
                }
            }
        }
    }
}

where is the problem? and what should I do to fix it?

1 Answers

from the part config you shared - I think that you have 2 sources jars

remove explicit sources jar in publishing

project(":$consumerMultibranchProjDir:soa-report-consumer-api") {
    jar {
        enabled = true
    }

    bootJar {
        enabled = false
    }
    archivesBaseName = "soa-report-consumer-api"
    version = "1.0.0-RELEASE"
    
    dependencies {
        api("com.sportswin.soa:soa-misc-biz:1.0.0-RELEASE")
        api project(":soa-wallet:soa-wallet-api")
    }

    publishing {
        publications {
            maven(MavenPublication) {
                groupId 'com.sportswin.soa'
                artifactId 'soa-report-consumer-api'
                version '1.0.0-RELEASE'
                from components.java
            }
        }
    }
}
Related