I want to publish multiple artifacts with different names with gradle and maven-publish
Asked Answered
B

0

6

I have a library containing usual classes and those especially for unit tests. So I want to publish two separate artifacts from the same project. My working solution with the maven plugin looks like this:

task jarTest (type: Jar, dependsOn: testClasses) {
    from sourceSets.test.output
    archiveBaseName.set('foo-test')
    description = 'test utilities'

}
artifacts {
    archives jarTest
}
uploadArchives {
    repositories {
        mavenDeployer {
            //...

            addFilter('foo') {artifact, file ->
                artifact.name == 'foo'
            }
            addFilter('foo-test') {artifact, file ->
                artifact.name == 'foo-test'
            }
        }
    }
}

Unfortunately the maven plugin is deprecated and will be removed in Gradle 7. maven-publish is the suggested replacement and I'm looking for a replacement solution.

My current attempt looks like

publishing {
    publications {
        mavenJava(MavenPublication) {
            artifact jar
            artifact jarTest
        }
    }
}

There is the obvious problem that there are two artifacts with the same name.

Setting the name like this does not work:

artifactId = jar.archiveBaseName

this neither:

afterEvaluate {
   artifactId = jar.archiveBaseName
}

It's possible to configure the artifact like this

artifact(jar) {
    classifier "src"
    extension "zip"
}

But there is no property for the name regarding the documentation (https://docs.gradle.org/current/dsl/org.gradle.api.publish.maven.MavenArtifact.html).

So I'm looking for sth. like the addFilter from the maven plugin.

Borderline answered 27/11, 2019 at 19:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.