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.28k stars 119 forks source link

Publishing to two repositories with different platform configurations #754

Open JakeWharton opened 6 months ago

JakeWharton commented 6 months ago

I want to publish to a repo-local maven repo (build/test-maven/) for testing, but also publish to Maven Central for releases. This works fine today, except that my test repo requires source and javadoc jars be generated. This means that Dokka has to run in order to test, and we have like 40+ modules so Dokka takes fooooorreeeeevveeeer.

As far as I can tell, the platform mechanism means that I can only choose to include sources/javadoc jars at the project-level once, and that configuration will be used by all publications. I believe that means there's no way to do what I want today then, right?

And if that's the case, maybe we could figure out an evolution to make this possible. Thanks!

gabrielittner commented 5 months ago

Making it dynamic based on which repository a publication is published to unfortunately won't work, since publications and repositories are independent from each other and it's not possible to modify a publication just for one repository.

When using the base plugin (or the main plugin but still calling configure(Platform)) like you mentioned you can make that decision for a project and you could make it conditional based on a property. What we could do to make this nicer for the main plugin is to have a default boolean Gradle properties for each for sources and javadoc. For programmatic configuration we can also boolean parameters to configureBasedOnAppliedPlugins (this is usually called by the main plugin in afterEvaluate and automatically configures the right platform if none was manually set).

JakeWharton commented 3 months ago

Yeah I don't think it needs to be dynamic. I'm okay with two publications targeted at the two repositories but sourced basically from the same tasks. One would only build the main artifacts, and the other would build the main artifacts and doc jars and source jars.

I guess the goal is to not have to duplicate too much where things like the coordinates and pom config would still be shared.

gabrielittner commented 2 days ago

As a simple first step using the same publications and everything, just having a config, you can do the following in the current release:

subprojects {
    plugins.withId("com.vanniktech.maven.publish") {
        extensions.configure(MavenPublishBaseExtension::class.java) {
            configureBasedOnAppliedPlugins(sourcesJar = false, javadocJar = false)
        }
    }
}

Caveats:

Would be interesting to know whether this is already helpful.