preface

Recently wrote an automated packaging upload dandelion tripartite platform, such as sending a message in the flying book group of robots, hands free, convenient testers download project, want to release to the remote server to call, but remember JCenter has announced on May 1, 2020 to stop the new library of submission (use only, can’t commit), Before February 21, 2022, even the library resolution service will be stopped, so try to publish the packaged library to Maven Central.

What tools are needed

1: sonatype

2: nexus

3: Github

The first step,Sonatype Jiraconfiguration

Like jCenter, Maven Central is run by Sonatype, so you first need to register a Sonatype account and get permission to use the repository.

registered

To register your account, go to Issues.sonatype.org. The interface is shown below:

Enter your email address, user name, and password to register successfully

Note: Email is very important and it is recommended that you use your usual email in order to receive a timely response to Sonatype in the issue.

After successful registration, return to the login page again and fill in the user name and password you just registered to complete the login in Sonatype, as shown in the following figure.

To register, you need to fill in your email address (important, please fill in your real email address), first name, user name (important, for login), password (complex password with symbols, English and numbers), and verification code.

Create a problem

As shown in the figure, we create a problem.

The only thing you need to pay attention to in this step is the Group Id. If you fill in the wrong Sonatype, the staff will give you an issue. There are two cases:

  • None Domain name: Use the github subdomain nameio.github.usernameFor example, my Github account name is Eegetsio.github.eegets.
  • Have website domain name: can fill in personal or company domain name, such as:com.eegetsIn addition, you also need to configure a TXT record in DNS configuration to verify domain name ownership, see:Central.sonatype.org/pages/produ…

After the issue is created, an administrator will process your issue and wait for the administrator to reply to your issue. Generally, one step is required: create an empty warehouse on Github. My empty warehouse name is osSRH-75861. The second is whether to modify groupId.

The administrator replied to me as follows:

When the problem status changes to resolved, it proves that our Sonatype project has completed the application, as shown in the figure below

Step 2: Gradle configuration

Next open your project and create a file in the root directory with a. Gradle extension: “publk-mavencentral. Gradle” :

This file is a common configuration file. You can directly copy and modify some configuration items in it

apply plugin: 'maven-publish'
apply plugin: 'signing'

task androidSourcesJar(type: Jar) {
    classifier = 'sources'

    exclude "**/R.class"  / / exclude ` R.c lass `
    exclude "**/BuildConfig.class"  . / / exclude ` BuildConfig class `
}
/ / 1
ext["signing.keyId"] = ' ' // The last 8 bits of the signed key
ext["signing.password"] = ' '  // The password of the signature
ext["signing.secretKeyRingFile"] = ' ' // The generated secring. GPG file directory
ext["ossrhUsername"] = ' '  / / sonatype user name
ext["ossrhPassword"] = ' '  / / sonatype password

File secretPropsFile = project.rootProject.file('local.properties')
if (secretPropsFile.exists()) {
    println "Found secret props file, loading props"
    Properties p = new Properties()
    p.load(new FileInputStream(secretPropsFile))
    p.each { name, value ->
        ext[name] = value
    }
} else {
    println "No props file, loading env vars"
}
publishing {
    publications {
        release(MavenPublication) {
            println("publish-maven Log-------> PUBLISH_GROUP_ID: $PUBLISH_GROUP_ID; PUBLISH_ARTIFACT_ID: $PUBLISH_ARTIFACT_ID; PUBLISH_VERSION: $PUBLISH_VERSION")
            // The coordinates of the library, being set from variables that
            
            / / 2
            groupId PUBLISH_GROUP_ID
            artifactId PUBLISH_ARTIFACT_ID
            version PUBLISH_VERSION

            // Two artifacts, the `aar` and the sources
            artifact(".. /plugin/com/eegets/plugin/upload/${PUBLISH_VERSION}/upload-${PUBLISH_VERSION}.jar")
            artifact androidSourcesJar

            // Self-explanatory metadata for the most part
            pom {        
                / / 3
                name = PUBLISH_ARTIFACT_ID
                description = 'Automatic packaging upload to dandelion and other tripartite platforms, free hands, convenient for testers to download' // Project description
                // If your project has a dedicated site, use its URL here
                url = 'https://github.com/eegets/UploadApkPlugin' // Project github link
                licenses {
                    license {
                        // The protocol type is Apache License2.0.
                        name = 'The Apache License, Version 2.0'
                        url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer {
                        / / 4
                        id = 'xxx' // Your Sonatype username
                        name = 'xxx' // Your Sonatype username
                        email = 'xxx' // Your Sonatype registered email address}}// Version control info, if you're using GitHub, follow the format as seen here
                scm {
                    / / 5
                    // Change it to your Git address:
                    connection = 'scm:[email protected]:eegets/UploadApkPlugin.git'
                    developerConnection = 'scm:[email protected]:eegets/UploadApkPlugin.git'
                    // Branch address:
                    url = 'https://github.com/eegets/UploadApkPlugin/tree/master'
                }
                // A slightly hacky fix so that your POM will include any transitive dependencies
                // that your library builds upon
                withXml {
                    def dependenciesNode = asNode().appendNode('dependencies')

                    project.configurations.implementation.allDependencies.each {
                        def dependencyNode = dependenciesNode.appendNode('dependency')
                        dependencyNode.appendNode('groupId', it.group)
                        dependencyNode.appendNode('artifactId', it.name)
                        dependencyNode.appendNode('version', it.version)
                    }
                }
            }
        }
    }
    repositories {
        // The repository to publish to, Sonatype/MavenCentral
        maven {
            / / 6
            name = "UploadApkPlugin"
            / / use 'https://s01.oss.sonatype.org' instead of 'https://oss.sonatype.org' here, Because 'https://oss.sonatype.org' will cause nexus background login failure and release 'Received status code 403 from server: Forbidden' problems
            def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
            def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
            // You only need this if you want to publish snapshots, otherwise just set the URL
            // to the release repo directly
            url = version.endsWith('SNAPSHOT')? snapshotsRepoUrl : releasesRepoUrl// The username and password we've fetched earlier
            credentials {
                username ossrhUsername
                password ossrhPassword
            }
        }
    }
}
signing {
    sign publishing.publications
}
Copy the code

As in the above code, we need to configure 6

1 place

Add the following configuration to the project root directory local.properties file

#// The last 8 bits of the secret key
signing.keyId=XXXX

#// The password set in Step 4
signing.password=XXXX

#// The generated secring. GPG file directory
signing.secretKeyRingFile=/Users/xxxx/xxxx/secring.gpg

#/ / sonatype user name
ossrhUsername=xxxx

#/ / sonatype password
ossrhPassword=xxxx
Copy the code

2 place

In the build.gradle file under the module to be submitted, add the following code:

Note: ext{} and apply from: ‘.. /publish-mavencentral. Gradle ‘/publish-mavencentral. Gradle’ /publish-mavencentral. Gradle ‘/publish-mavencentral

ext {
    PUBLISH_ARTIFACT_ID = "uploadPlugin" // Your artifact_id is usually the name of the module
    PUBLISH_VERSION = "1.0.3"  // Release version number
    PUBLISH_GROUP_ID = 'xxx'  // Group_id of your Sonatype
}
apply from: '.. /publish-mavencentral.gradle'
Copy the code

The third place

In publish-mavencentral.gradle configure the project description and GitHub address of the project as follows:

name = PUBLISH_ARTIFACT_ID description = 'Project Description' // Project description

url = 'https://github.com/eegets/UploadApkPlugin' // Project github link
Copy the code

The fourth place

Configure sonatype information as follows:

id = 'xxx' // Your Sonatype username
name = 'xxx' // Your Sonatype username
email = 'xxx' // Your Sonatype registered email address
Copy the code

The fifth place

Configure Github information as follows:


connection = 'scm:[email protected]:eegets/UploadApkPlugin.git'  // Branch address

developerConnection = 'scm:[email protected]:eegets/UploadApkPlugin.git' // Branch address:

url = 'https://github.com/eegets/UploadApkPlugin/tree/master'
Copy the code

6 place

Configure the project name and publishing address

name = "UploadApkPlugin" 

releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" def 

snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
Copy the code

Note: Here to replace https://oss.sonatype.org with https://s01.oss.sonatype.org, The nexus background fails to log in to https://oss.sonatype.org and Received status code 403 from server: Forbidden is displayed during the release

Create the GPG secret key

  1. www.gnupg.org/download/, download and install the GPG client from here. Mine is a MAC, so select one of the boxes below and click Install Next. The following figure

  1. After the installation is successful, open the terminal and run commands on the CLIgpg --full-gen-keyNote that the command must be executed on the command line rather than the client interface.

  1. As shown in the figure above, the encryption mode is RSA and RSA, the length is 4096, and the expiration time is directly entered. Then enter a user ID and provide an email address. I directly use my Sonatype user name and email address. In the last step, type ‘O’ for OK.

  2. A dialog box will pop up asking you to enter your password.

gpg: revocation certificate stored as ‘~/.gnupg/openpgp-revocs.d/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXE478F7CC.rev’ public and secret key created and signed.

pub rsa4096 2021-03-22 [SC] XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXEE478F7CC uid boybeak [email protected] sub rsa4096 2021-03-22 [E] “`

This will create a.rev file for you in ~/.gnupg/ openPgp-revocs.d /, remembering the last 8 bits of pub.

  1. Next create the secring. GPG file and execute it from the command linegpg --export-secret-keys -o secring.gpgThis will ask you to enter the password you set in Step 4. The secring.gpg file will appear in your project root directory. Since I am executing in the current project directory, the secring. GPG file is generated in the project root directory. The diagram below:

  1. Go back to the GPG client, select the key entry we just generated, right-click, and selectSend Public Key to Key Server. Remember the last eight bits, circled below:

After the above configuration of GPG, we can improve our step 1 above.

local.propertiesconfiguration

#// The last 8 bits of the secret key
signing.keyId=XXXX

#// The password set in Step 4
signing.password=XXXX

#// The generated secring. GPG file directory
signing.secretKeyRingFile=/Users/xxxx/xxxx/secring.gpg

#/ / sonatype user name
ossrhUsername=xxxx

#/ / sonatype password
ossrhPassword=xxxx
Copy the code

Perform packing and uploading

Once you’ve set this up, go to gradle tasks on the right of AndroidStudio and find the module you want to submit. Perform the following two tasks.

With all of the above configuration, packaging and uploading should be successful without accident [if compilation fails, please reread the above article]

After uploading successfully, open Nexus Repository Manager, log in to your Sonatype account, find your group ID in the left Staging Repositories page, select it, click Close, wait a few minutes and refresh the status. Once it’s closed, click Release and everyone can use your library.

Note: it is better to go to https://s01.oss.sonatype.org, https://oss.sonatype.org inaccessible, reason please see: issues.sonatype.org/browse/OSSR…

Next, you need to wait for a checkmark “Repository Closed” to appear on the Activity TAB and then click the Release button to publish to MavenCentral. Wait a few hours for the results to be published at search.maven.org/.

Missing: No Javadoc JAR found in Folder

According to the above way, we can complete the package and release of Maven. If the Close fails when nexus performs the last Close, and: Missing: Missing: No Javadoc jar found in Folder Missing: No Javadoc jar found in Folder No Javadoc JAR found in Folder

Pay attention to the above several quotes need to pay attention to the place, these attention can wish you avoid pits!!

The source code

Github.com/eegets/Uplo…

The resources

  • Android library to Maven Central overview
  • Publish Android libraries to mavan Central tutorials