Skip to content

How to make & publish a library to Maven Central #1

@busmaker

Description

@busmaker

This shit job is very compilcated not hard, I feel it's totally necessary to make a record for this shit.

  1. Get an account from Sonatype.

  2. Request group-id by create an Issue

     Project: Community Support - Open Source Project Repository Hosting (OSSRH)
     Issue Type: New Project
    
  3. Create a repo on github named with issue id

  4. Create a library project using Intellij IDEA

  5. Download GPG

  6. Run gpg commands
    gpg --full-generate-key
    generates the key for signing your library

    gpg --armor --export your-key-username
    it prints public key in hex, copy & submit it to keyserver.ubuntu.com or keys.gnupg.net

  7. gpg --keyring key.gpg --export-secret-keys
    it exports the key to key.gpg, copy it to the root of library directory

    gpg --list-keys --keyid-format short
    copy the short-key-id

  8. create a file named gradle.properties in the root of library directory with content:

signing.keyId=short-key-id 
signing.password=password
signing.secretKeyRingFile=key.gpg
  1. add this to the build.gradle
plugins {
    id 'java'
    id 'maven-publish'
    id 'signing'
}

group 'io.github.hqktech'
version '1.0'
javadoc {
    options {
        encoding = "UTF-8"
    }
}

java {
    withJavadocJar()
    withSourcesJar()
}
publishing {
    repositories {
        maven {
            url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
            credentials {
                username = username
                password = password
            }
        }
    }

    publications {
        mavenJava(MavenPublication) {
            from components.java
            pom {
                groupId = 'io.github.hqktech'
                name = 'jdwp'
                description = 'A jdwp encoding & decoding library'
                url = 'https://github.com/hqktech/jdwp'
                developers {
                    developer {
                        id = 'LBJ-the-GOAT'
                        name = 'LBJ-the-GOAT'
                        email = 'LBJ-the-GOAT@hotmail.com'
                    }
                }
                licenses {
                    license {
                        name = 'The Apache License, Version 2.0'
                        url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                scm {
                    connection = 'scm:git:git@github.com:github.com/hqktech/jdwp.git'
                    developerConnection = 'scm:git:git@github.com:github.com/hqktech/jdwp.git'
                    url = 'https://github.com/hqktech/jdwp'
                }
            }
        }
    }
}

signing {
    sign publishing.publications.mavenJava
}

repositories {
    mavenCentral()
}

  1. Run this gradle, if successfully it will upload the jars to the OSSNH
  2. Go to (Nexus Repository Manager)[https://s01.oss.sonatype.org/] select the library just updated, close it & release it
  3. Go back to issue page of step 2 and ask for activate sync to maven central.

After 10 minutes after activated the library can be visited on repo1 maven and may be 2 hours later it's sync to Maven Central

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions