简体   繁体   中英

Maven - Publishing Multiple Sub-Modules/Artifacts

I have a Kotlin project organised like so:

project-name
    > project-name-core
    > project-name-domain

My gradle publishing script is set up like this:

publishing {
    repositories {
        mavenLocal()
    }
    publications.all {
        pom.withXml(configureMavenCentralMetadata)
    }
    publications {
        mavenPublication(MavenPublication) {
            from components.java
            groupId 'com.project'
            artifactId 'project-name'
            artifact sourcesJar
            artifact javadocJar
        }
    }
}

When I run ./gradlew publishToMavenLocal I can see project-name in the local repository cache, but not project-name-core or project-name-domain .

How do I configure gradle to publish my sub-modules to the maven local repository cache?

Best guess is that you only applied the publishing plugin to the root project and not the subprojects.

If you intend to publish the root project ( src/ ) in addition to the subprojects, then you should move the configurations to the allprojects block:

allprojects {
    publishing {
        publications.all {
            pom.withXml(configureMavenCentralMetadata)
        }
        publications {
            mavenPublication(MavenPublication) {
                from components.java
                groupId 'com.project'
                artifactId 'project-name'
                artifact sourcesJar
                artifact javadocJar
            }
        }
    }
}

Otherwise if you only want to publish the subprojects, then replace allprojects with subprojects

Also, you don't need to add configure the repositories with mavenLocal() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM