vanniktech / gradle-maven-publish-plugin

A Gradle plugin that publishes your Android and Kotlin libraries, including sources and javadoc, to Maven Central or any other Nexus instance.
https://vanniktech.github.io/gradle-maven-publish-plugin
Apache License 2.0
1.31k stars 120 forks source link

Question: Publish feature #864

Open mingchiuli opened 3 weeks ago

mingchiuli commented 3 weeks ago

The Document of gradle publish describe that Depending on the metadata file format, publishing features may be loss if some config were lost. I found the generated maven xml label of optional would be lost if i publish package via ./gradlew publishAndReleaseToMavenCentral.

Expectation:

    <dependency>
      <groupId>org.springframework.amqp</groupId>
      <artifactId>spring-rabbit</artifactId>
      <scope>runtime</scope>
      <optional>true</optional>
    </dependency>

Fact:

    <dependency>
      <groupId>org.springframework.amqp</groupId>
      <artifactId>spring-rabbit</artifactId>
      <scope>runtime</scope>
    </dependency>

My gradle setting is:

import com.vanniktech.maven.publish.SonatypeHost

version = "1.0.1"

plugins {
    id("com.vanniktech.maven.publish") version "0.30.0"
}

mavenPublishing {
    publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
    signAllPublications()

    coordinates("$group", "cache-spring-boot-starter", "$version")

    pom {
        name.set("Megalith Cache")
        description.set("A Cache Framework for Megalith")
        inceptionYear.set("2024")
        url.set("https://github.com/mingchiuli/megalith-micro/")
        licenses {
            license {
                name.set("The Apache License, Version 2.0")
                url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
                distribution.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
            }
        }
        developers {
            developer {
                id.set("chiu")
                name.set("mingchiuli")
                url.set("https://github.com/mingchiuli/")
            }
        }
        scm {
            url.set("https://github.com/mingchiuli/megalith-micro/")
            connection.set("scm:git:git://github.com/mingchiuli/megalith-micro.git")
            developerConnection.set("scm:git:ssh://git@github.com/mingchiuli/megalith-micro.git")
        }
    }
}

sourceSets {
    create("rabbitmqSupport") {
        java {
            srcDirs("/src/rabbitmq/java")
            resources.srcDir("/src/rabbitmq/resources")
        }
    }
}

java {
    registerFeature("rabbitmqSupport") {
        usingSourceSet(sourceSets["rabbitmqSupport"])
        capability("$group", "cache-rabbit-support", "$version")
    }
}

dependencies {
    implementation("org.redisson:redisson:${ext.get("redisson.version")}")
    implementation("com.github.ben-manes.caffeine:caffeine")
    implementation("org.aspectj:aspectjweaver")
    sourceSets.named("rabbitmqSupport") {
        implementation("org.springframework.amqp:spring-rabbit")
    }
    compileOnly("jakarta.servlet:jakarta.servlet-api")
    compileOnly("org.springframework:spring-context")
    compileOnly("org.springframework:spring-core")
    compileOnly("org.springframework:spring-web")
    compileOnly("org.springframework.boot:spring-boot-autoconfigure")
}

Is there some methods here to add the label of optional?