Code Monkey home page Code Monkey logo

nmcp's Introduction

Nmcp: New Maven Central Publishing (or New Maven Central Portal too!)

A plugin that uses the new Central Portal publisher API to publish to Maven Central.

New accounts created after Feb. 1st 2024 are configured to use the new publishing by default and can use this plugin. Other accounts can continue publishing to OSSRH the usual way.

Warning

Nmcp does not create publications or apply the maven-publish plugin. This must be done using other means. Nmcp uses existing publications, stages them locally and uploads a zip to the Central Portal publisher API. To configure the publications, you can use vanniktech/gradle-maven-publish-plugin and call nmcp publishAllPublicationsToCentralPortal instead of vanniktech publishAndReleaseToMavenCentral.

See StylianosGakis/molecule-aacvm for an example.

Note

This project was created as a short term solution and a good learning opportunity. I'm hoping more streamlined solutions will appear in the long run, either in gradle-maven-publish-plugin or as first party.

QuickStart:

Configure nmcp in your root project using the quick way:

// root/build.gradle[.kts]
plugins {
    id("com.gradleup.nmcp").version("0.0.7")
}

nmcp {
  publishAllProjectsProbablyBreakingProjectIsolation {
    username = TODO()
    password = TODO()
    // publish manually from the portal
    publicationType = "USER_MANAGED"
    // or if you want to publish automatically
    publicationType = "AUTOMATIC"
  }
}

Then call publishAllPublicationsToCentralPortal to publish all your publications:

./gradlew publishAllPublicationsToCentralPortal
# yay everything is uploaded ๐ŸŽ‰
# go to https://central.sonatype.com/ to release if you used USER_MANAGED

Project isolation compatible version:

publishAllProjectsProbablyBreakingProjectIsolation uses the allprojects {} block and might be incompatible with Project-isolation.

You can be 100% compatible by adding the plugin to each module you want to publish:

//root/moduleN/build.gradle.kts
plugins {
    id("com.gradleup.nmcp").version("0.0.7")
}

nmcp {
  publishAllPublications {}
}

And then list all modules in your root project:

//root/build.gradle.kts
plugins {
    id("com.gradleup.nmcp").version("0.0.7")
}

nmcp {
    publishAggregation {
        project(":module1")
        project(":module2")
        project(":module3")

        username = TODO()
        password = TODO()
        publicationType = "USER_MANAGED"
    }
}

Single-module:

plugins {
    id("com.gradleup.nmcp").version("0.0.7")
}

// Create your publications

nmcp {
    // nameOfYourPublication must point to an existing publication
    publish(nameOfYourPublication) {
        username = TODO("Create a token at https://central.sonatype.com/account") 
        password = TODO("Create a token at https://central.sonatype.com/account")
        // publish manually from the portal
        publicationType = "USER_MANAGED"
        // or if you want to publish automatically
        publicationType = "AUTOMATIC"
    }
}

nmcp's People

Contributors

martinbonnin avatar stylianosgakis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nmcp's Issues

Please add license

I would like to use this plugin but I don't see a license. Can you please add one?

Perhaps Apache License 2.0

Thanks in advance

unknown property 'username'

I'm getting the following error:

Could not set unknown property 'username' for object of type nmcp.NmcpExtension

In my build.gradle file I have

nmcp {
    publishAllProjectsProbablyBreakingProjectIsolation  {
        username = findProperty('sonatypeUsername') as String
        password = findProperty('sonatypePassword') as String
        publicationType = 'USER_MANAGED'
    }
}

no configured signatory issue

I have two plugins files under module - convention-plugins which comming from - https://github.com/Kotlin/multiplatform-library-template/tree/main/convention-plugins

was trying to migrate to your plugin but i got some errors.

module.publication.gradle.kts

import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.`maven-publish`

plugins {
    id("com.gradleup.nmcp")
    `maven-publish`
    signing
}


nmcp {
    publishAllPublications {}
}

signing {
    val signingKey: String? by project
    val signingKeyId: String? by project
    val signingPassword: String? by project
    useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
    sign(publishing.publications)
}

publishing {
    // Configure all publications
    publications.withType<MavenPublication> {
        // Stub javadoc.jar artifact
        artifact(tasks.register("${name}JavadocJar", Jar::class) {
            archiveClassifier.set("javadoc")
            archiveAppendix.set([email protected])
        })

        // Provide artifacts information required by Maven Central
        pom {
            name.set("Kotlin Multiplatform library template")
            description.set("Dummy library to test deployment to Maven Central")
            url.set("https://github.com/Kotlin/multiplatform-library-template")

            licenses {
                license {
                    name.set("MIT")
                    url.set("https://opensource.org/licenses/MIT")
                }
            }
            developers {
                developer {
                    id.set("JetBrains")
                    name.set("JetBrains Team")
                    organization.set("JetBrains")
                    organizationUrl.set("https://www.jetbrains.com")
                }
            }
            scm {
                url.set("https://github.com/Kotlin/multiplatform-library-template")
            }
        }
    }
}

and root.publication.gradle.kts

plugins {
    id("com.gradleup.nmcp")
    id("maven-publish")
}

nmcp {
    publishAggregation {
        project(":openai-client")
        project(":openai-client:openai-client-core")
        project(":openai-client:openai-client-darwin")
        project(":openai-client:openai-client-cio")
        publicationType = "AUTOMATIC"
    }
}

but when run gradle publish i got an error below:

Execution failed for task ':openai-client:openai-client-cio:signJvmPublication'.
> Cannot perform signing task ':openai-client:openai-client-cio:signJvmPublication' because it has no configured signatory

Missing "publicationName" in 0.0.5

After upgrading to 0.0.5 I have an error when I try to publish my project:

> Task :publishAggregatedPublicationToCentralPortal FAILED

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':publishAggregatedPublicationToCentralPortal' (type 'NmcpPublishTask').
  - In plugin 'com.gradleup.nmcp' type 'nmcp.NmcpPublishTask' property 'publicationName' doesn't have a configured value.
    
    Reason: This property isn't marked as optional and no value has been configured.
    
    Possible solutions:
      1. Assign a value to 'publicationName'.
      2. Mark property 'publicationName' as optional.

Consider allowing the `publication.zip` name which is published to the portal to be altered

I recently used this again to publish a second library (crazy, I know ๐Ÿ˜…) and I realized in the publishing list it's just a long list of the same name
image
Making it actually indistinguishable from each other. It literally has a Deployment ID and a date, I have no idea what it is for when I press publish ๐Ÿ˜…

Probably something for them to fix in some way to make that UI a bit more friendly, but until then this could at least help me name the zip file to the library name, if not even with the version name? Not sure if that'd break anything. And not sure if the nmcp library do something more internally to get the version number or whatever. This should be a great minimal effort -> great benefit change.

I am really really not familiar with working with plugins like this so I'm gonna make a best effort PR, but I am not 100% sure how I could test it locally either. Lmk if I should change something :D

Also this assumes that one can just name this whatever. Not sure if the API would be happy with that ๐Ÿ‘€

Can't publish multiplatform library

I have a project with commonMain, jsMain and jvmMain targets. When I used same configuration with jvm project and it's works fine. But with KMP project I get an error

Configuration:

plugins {
    id("maven-publish")
    kotlin("multiplatform") version "1.9.10"
    signing
    id("com.gradleup.nmcp") version "0.0.7"
}

repositories {
    mavenCentral()
}

kotlin {
    jvm {
        jvmToolchain(8)
        withJava()
        testRuns.named("test") {
            executionTask.configure {
                useJUnitPlatform()
            }
        }
        withSourcesJar()
    }
    js(IR) {
        browser {
            commonWebpackConfig(Action {
                cssSupport {
                    enabled.set(true)
                }
            })
        }
    }

    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val jvmMain by getting
        val jvmTest by getting
        val jsMain by getting
        val jsTest by getting
    }
}

allprojects {
    group = "ru.raysmith"
    version = "2.5.1"

    tasks {
        withType<KotlinCompile> {
            kotlinOptions {
                freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn"
                jvmTarget = JavaVersion.VERSION_1_8.toString()
            }
        }
        withType<Test> {
            useJUnitPlatform()
        }
        withType<PublishToMavenRepository> {
            dependsOn(check)
        }
    }
}
publishing {
    publications {
        create<MavenPublication>("release") {
            artifactId = project.name
            groupId = project.group.toString()
            version = project.version.toString()
            from(components["java"])
            pom {
                packaging = "jar"
                name.set("Google")
                url.set("https://github.com/RaySmith-ttc/utils")
                description.set("Basic module with utils")

                licenses {
                    license {
                        name.set("The Apache License, Version 2.0")
                        url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
                    }
                }

                scm {
                    connection.set("scm:https://github.com/RaySmith-ttc/utils.git")
                    developerConnection.set("scm:[email protected]:RaySmith-ttc/utils.git")
                    url.set("https://github.com/RaySmith-ttc/utils")
                }

                developers {
                    developer {
                        id.set("RaySmith-ttc")
                        name.set("Ray Smith")
                        email.set("[email protected]")
                    }
                }
            }
        }
    }
    repositories {
        maven {
            name = "OSSRH"
            val releasesUrl = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
            val snapshotsUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
            url = if (version.toString().matches(".*(SNAPSHOT|rc.\\d+)".toRegex())) snapshotsUrl else releasesUrl
            credentials {
                username = System.getenv("SONATYPE_USER")
                password = System.getenv("SONATYPE_PASS")
            }
        }
    }
}

nmcp {
    publish("release") {
        username.set(System.getenv("CENTRAL_SONATYPE_USER"))
        password.set(System.getenv("CENTRAL_SONATYPE_PASS"))
        publicationType.set("USER_MANAGED")
        publicationType.set("AUTOMATIC")
    }
}

signing {
    sign(configurations.archives.get())
    sign(publishing.publications["release"])
}

Error:

> Task :jsProcessResources NO-SOURCE
> Task :jsTestProcessResources NO-SOURCE
> Task :kotlinNodeJsSetup
> Task :kotlinNpmCachesSetup
> Task :kotlinRestoreYarnLock
> Task :kotlinYarnSetup
> Task :jsPackageJson
> Task :jsTestPackageJson
> Task :jsPublicPackageJson
> Task :jsTestPublicPackageJson
> Task :packageJsonUmbrella
> Task :rootPackageJson
> Task :kotlinNpmInstall
> Task :kotlinStoreYarnLock
> Task :jvmProcessResources NO-SOURCE
> Task :processResources SKIPPED
> Task :jvmTestProcessResources UP-TO-DATE
> Task :processTestResources SKIPPED
> Task :generatePomFileForReleasePublication
> Task :compileKotlinJs
> Task :jsMainClasses
> Task :compileTestKotlinJs
> Task :jsTestClasses
> Task :compileKotlinJvm
> Task :compileJava NO-SOURCE
> Task :classes UP-TO-DATE
> Task :jvmMainClasses
> Task :jvmJar UP-TO-DATE
> Task :jar SKIPPED
> Task :generateMetadataFileForReleasePublication
> Task :compileTestDevelopmentExecutableKotlinJs
> Task :compileTestKotlinJvm
> Task :jsTestTestDevelopmentExecutableCompileSync
> Task :jsBrowserTest
> Task :jsTest
> Task :compileTestJava NO-SOURCE
> Task :jvmTestClasses
> Task :jvmTest
> Task :allTests
> Task :testClasses UP-TO-DATE
> Task :test SKIPPED
> Task :check
> Task :signReleasePublication
> Task :publishReleasePublicationToNmcpReleaseRepository FAILED

* What went wrong:
Execution failed for task ':publishReleasePublicationToNmcpReleaseRepository'.
> Failed to publish publication 'release' to repository 'nmcpRelease'
   > Artifact utils-jvm-2.5.1.jar wasn't produced by this build.

In fact, the file utils-jvm-2.5.1.jar was created in /build/libs also like utils-js-2.5.1.klib

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.