{"id":972,"date":"2019-12-02T13:56:59","date_gmt":"2019-12-02T00:56:59","guid":{"rendered":"https:\/\/www.ronella.xyz\/?p=972"},"modified":"2023-08-18T09:12:47","modified_gmt":"2023-08-17T21:12:47","slug":"publishing-to-maven-central-with-gradle","status":"publish","type":"post","link":"https:\/\/www.ronella.xyz\/?p=972","title":{"rendered":"Publishing to Maven Central with Gradle"},"content":{"rendered":"<h1>Pre-requisites<\/h1>\n<ol>\n<li><strong>Create an account<\/strong> to <a href=\"https:\/\/www.sonatype.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">sonatype<\/a>.<\/li>\n<li><strong>Request for a group id<\/strong> from sonatype by using Jira to <a href=\"https:\/\/issues.sonatype.org\/secure\/CreateIssue.jspa?issuetype=21&amp;pid=10134\" target=\"_blank\" rel=\"noopener noreferrer\">create an issue<\/a>.<\/li>\n<li>Generate <strong>PGP keys<\/strong> to be used for signing the binaries <em>(e.g. jar file)<\/em>. <em>For windows, you can follow the procedure <a href=\"https:\/\/www.ronella.xyz\/?p=989\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/em><\/li>\n<li><strong>Wait<\/strong> for the completion of the issue you've created from item 2.<\/li>\n<\/ol>\n<h1>Gradle Configuration<\/h1>\n<ol>\n<li>Update your <strong>gradle.properties<\/strong> to include the following properties:\n<pre style=\"white-space: pre;\">nexusUsername=&lt;SONATYPE_USERNAME&gt;\nnexusPassword=&lt;SONATYPE_PASSWORD&gt;\n\nsigning.keyId=&lt;PGP_PUBLIC_KEY_ID&gt;\nsigning.password=&lt;PGP_PASS_PHRASE&gt;\nsigning.secretKeyRingFile=&lt;PGP_EXPORTED_PRIVATE_KEY&gt;\n<\/pre>\n<\/li>\n<li>In your <strong>build.gradle<\/strong> file,\u00a0 add the <a href=\"https:\/\/github.com\/bmuschko\/gradle-nexus-plugin\" target=\"_blank\" rel=\"noopener noreferrer\">Gradle Sonatype Nexus Plugin<\/a> like the following:\n<pre style=\"white-space: pre;\">plugins {\n   id \"java\"\n   id \"com.bmuschko.nexus\" version \"2.3.1\" \/\/ Gradle Sonatype Nexus Plugin\n}<\/pre>\n<\/li>\n<li>Add the following plugin configurations:\n<pre style=\"white-space: pre;\">modifyPom {\n    project {\n        name '&lt;PROJECT_NAME&gt;'\n        description '&lt;PROJECT_DESCRIPTION&gt;'\n        url '&lt;PROJECT_WEBSITE&gt;'\n        inceptionYear '&lt;PROJECT_INCEPTION_YEAR&gt;'\n\n        scm {\n            url '&lt;PROJECT_SCM_ADDRESS&gt;'\n            connection '&lt;PROJECT_SCM_ADDRESS&gt;'\n            developerConnection '&lt;PROJECT_SCM_ADDRESS&gt;'\n        }\n\n        licenses {\n            license {\n                name '&lt;PROJECT_LICENSE_NAME&gt;'\n                url '&lt;PROJECT_LICENSE_ADDRESS&gt;'\n                distribution 'repo'\n            }\n        }\n\n        developers {\n            developer {\n                id '&lt;DEVELOPER_ID&gt;'\n                name '&lt;DEVELOPER_NAME&gt;'\n                email '&lt;DEVELOPER_EMAIL&gt;'\n            }\n        }\n    }\n}\n\nextraArchive {\n    sources = true\n    tests = true\n    javadoc = true\n}\n\nnexus {\n    sign = true\n    repositoryUrl = '&lt;SONATYPE_RELEASE_REPOSITORY&gt;'\n    snapshotRepositoryUrl = '&lt;SONATYPE_SNAPSHOT_REPOSITORY&gt;'\n}<\/pre>\n<\/li>\n<li>Add the <a href=\"https:\/\/github.com\/Codearte\/gradle-nexus-staging-plugin\" target=\"_blank\" rel=\"noopener noreferrer\">Gradle Nexus Staging plugin<\/a> like the following:\n<pre style=\"white-space: pre;\">plugins {\n    id 'java'\n    id \"com.bmuschko.nexus\" version \"2.3.1\" \/\/ Gradle Sonatype Nexux Plugin\n    id \"io.codearte.nexus-staging\" version \"0.21.1\" \/\/ Gradle Nexus Staging Plugin\n}<\/pre>\n<\/li>\n<li>After adding the plugin save the build.gradle file.<\/li>\n<li>Get the <strong>staging profile ID<\/strong> by running the following command:\n<pre style=\"white-space: pre;\">gradlew getStagingProfile<\/pre>\n<\/li>\n<li>Add the following plugin configuration:\n<pre style=\"white-space: pre;\">nexusStaging {\n    stagingProfileId = \"&lt;STAGING_PROFILE_ID&gt;\"\n}<\/pre>\n<\/li>\n<li>Save the <strong>build.gradle<\/strong> file again.<\/li>\n<\/ol>\n<h1>Uploading to Sonatype Repository<\/h1>\n<p>Run the following command:<\/p>\n<pre style=\"white-space: pre;\">gradlew publishToSonatype<\/pre>\n<h1>Publishing to Maven Central<\/h1>\n<p>Run the following command:<\/p>\n<pre style=\"white-space: pre;\">gradlew closeAndReleaseSonatypeStagingRepository<\/pre>\n<h4>Errors in Publishing<\/h4>\n<p>If there are any errors after running the preceding command<\/p>\n<ol>\n<li><strong>Sign in<\/strong> to the following address using your <strong>sonatype credentials<\/strong>: <a href=\"https:\/\/oss.sonatype.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/oss.sonatype.org\/<\/a><\/li>\n<li>Click the <strong>Staging Repositories<\/strong> menu and investigate the error from there.<\/li>\n<li>Once the errors were identified and corrected locally, upload it again to sonatype repository before publishing it again.<\/li>\n<\/ol>\n<blockquote><p>Do this error correction process until all the errors were corrected.<\/p><\/blockquote>\n<h4>Successful Publishing Validation<\/h4>\n<p>After around <strong>10 minutes<\/strong>, navigate to your <strong>registered group id from sonatype<\/strong>, starting from the following address:<\/p>\n<p><a href=\"https:\/\/repo.maven.apache.org\/maven2\/\" target=\"_blank\" rel=\"noopener noreferrer\"><a href=\"https:\/\/repo.maven.apache.org\/maven2\/\">https:\/\/repo.maven.apache.org\/maven2\/<\/a><\/a><\/p>\n<p>After around <strong>2 hours<\/strong>, your <strong>artifact id<\/strong> may be searchable in maven central from the following address:<\/p>\n<p><a href=\"https:\/\/search.maven.org\/\" target=\"_blank\" rel=\"noopener noreferrer\"><a href=\"https:\/\/search.maven.org\/\">https:\/\/search.maven.org\/<\/a><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pre-requisites Create an account to sonatype. Request for a group id from sonatype by using Jira to create an issue. Generate PGP keys to be used for signing the binaries (e.g. jar file). For windows, you can follow the procedure here. Wait for the completion of the issue you&#8217;ve created from item 2. Gradle Configuration [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[32,17,49],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/972"}],"collection":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=972"}],"version-history":[{"count":18,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/972\/revisions"}],"predecessor-version":[{"id":1609,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/972\/revisions\/1609"}],"wp:attachment":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=972"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=972"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=972"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}