Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publishing to two repositories with different platform configurations #754

Open
JakeWharton opened this issue Apr 4, 2024 · 3 comments
Open
Labels

Comments

@JakeWharton
Copy link

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
Copy link
Collaborator

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
Copy link
Author

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
Copy link
Collaborator

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:

  • configureBasedOnAppliedPlugins needs to be called after other plugins that determine what gets published are applied (e.g. Kotlin or Android plugins) but before afterEvaluate. So for the snippet above the publish plugin would need be applied after the Java/Kotlin/Android plugin.
  • For some project types it might still produce empty source jars, but since the goal is to save time that should be fine.
  • Doesn't have an effect on projects using com.gradle.plugin-publish

Would be interesting to know whether this is already helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants