How to publish with classifier to maven repo

I am using the maven-publish and want to publish multiple artifacts with various classifier

According to the guideline, i use the following method to mention the classifier for javadoc and aar.

publishing {
    publications {
        maven(MavenPublication) {
            artifact source: file("${project.buildDir}/outputs/aar/${}-${project.version}.aar"),classifier:"aar",extension:"aar"
        maven(MavenPublication) {
            artifact source: file("${project.buildDir}/docs/"), classifier:"javadoc", extension:"zip"

Two files are uploaded properly.

However, the pom.xml is something like this. It seems the classifier is not properly set. Any ideas on how to set classifier ?

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="" xmlns=""

In the usual case, one of the artifacts is published without a classifier, and the pom does not define a classifier. Where no artifacts are published without a classifier, Gradle would need to guess which artifact was the ‘primary’ artifact and include that in the pom. Gradle doesn’t do this (yet).

You’ll need to use MavenPom.withXml to insert the classifier you require.