From JCenter to Maven or a short post on publishing Kotlin multiplatform

Recently, there was news that JCenter will soon be closed and how we can continue to live there is not said we need to move somewhere else. For me personally, MavenCentral has become the main candidate, since I have been publishing there for a long time, although for the last year I got used to doing it through Bintray. In this post, there will be brief information about the underwater ones I met and how I had to change my publishing scripts.





THIS ARTICLE DOES NO INFORMATION ABOUT THE PUBLICATION OF NATIVE TARGETS . Nevertheless, I hope the information in the article will be useful to you.





Probably already wrote

Indeed, there are several articles on this topic ( 2019 and 2021 ), but at the moment I have not seen a single full article with information about publication scripts (probably, I just looked in the wrong place). Used on most of the information can be taken from an article (registration Sonatype, domain registration, creating GPG key and its purpose and not only). The following is a universal script for publishing a multiplatform project:





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

task javadocsJar(type: Jar) { // ,  javadocs     
    classifier = 'javadoc'
}

publishing {
    publications.all {
        artifact javadocsJar

        pom {
            description = "  "
            name = "${project.name}"
            url = "https://github.com/Owner/Project" //     ,     github

            scm {
                developerConnection = "scm:git:[fetch=]/*   .git */[push=]/*  */"
                url = "/*    */"
            }

            developers {
                    developer {
                        id = "ID "
                        name = " "
                        email = "email "
                    }
            }

            licenses {
                    license {
                        name = " "
                        url = "  LICENSE "
                    }
                
            }
        }
        
        repositories {
            //   Maven Central
            maven {
                name = "sonatype"
                url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
                credentials {
                    username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
                    password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
                }
            }
        }
    }
}

signing {
    useGpgCmd()
    sign publishing.publications
}

      
      



You can see an example of this script here . While moving from JCenter, I encountered the following errors:





  • maven url uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")







  • publishing.publications ( , Java ( Android) )





gradle SONATYPE_USER



SONATYPE_PASSWORD



. :





  • ~/.gradle/gradle.properties







  • ( CI )





, . :





$ ./gradlew --no-parallel publishAllPublicationsToSonatypeRepository
      
      



--no-parallel



here it is used for the reason that if you use parallel building of the project (flag --parallel



or org.gradle.parallel=true



in gradle.properties



), then without the flag of disabling parallel building, the publication will be made to several repositories, which may entail the inability to close and publish releases (this was also written about in articles above).





Instead of a conclusion

Publishing a library is difficult, so I sincerely wish you the best in this endeavor. If there are comments / additions or something else that can help others, write in the comments so that I add a note about this to the article. Good luck.








All Articles