Publish Kotlin SDKs manually

View as Markdown

This guide covers publishing Kotlin SDKs manually. For information on automating Kotlin SDK publishing, see Publish Kotlin SDKs automatically.

To share your generated Kotlin SDK with the community, you can publish it to Maven Central. This enables other developers to easily add it as a dependency in their Maven or Gradle projects. Follow the steps below to publish your SDK to Maven Central.

Prerequisites

To publish your SDK to Maven Central, you need the following:

  • Sonatype Central Portal account (central.sonatype.com).
  • GPG key for signing artifacts.
  • Namespace (group ID) verified on the Central Portal.

Initial setup

To set up your environment for publishing to Maven Central, do the following:

  1. Create account and verify your namespace:

    • Register at central.sonatype.com.
    • Verify your namespace (group ID, for example, com.example) through DNS or GitHub verification.
    • Verification is typically automated and completes within minutes.
  2. Generate a GPG key.

    $gpg --gen-key
    $gpg --list-keys
    $gpg --keyserver keys.openpgp.org --send-keys YOUR_KEY_ID
  3. Configure Maven settings.xml. Add the following to ~/.m2/settings.xml:

    1<settings>
    2<servers>
    3 <server>
    4 <id>central</id>
    5 <username>your-central-portal-token-username</username>
    6 <password>your-central-portal-token-password</password>
    7 </server>
    8</servers>
    9<profiles>
    10 <profile>
    11 <id>central</id>
    12 <activation>
    13 <activeByDefault>true</activeByDefault>
    14 </activation>
    15 <properties>
    16 <gpg.executable>gpg</gpg.executable>
    17 <gpg.passphrase>your-gpg-passphrase</gpg.passphrase>
    18 </properties>
    19 </profile>
    20</profiles>
    21</settings>

Configure pom.xml

Add the following to your SDK’s pom.xml:

1<project>
2 <!-- Basic information -->
3 <groupId>com.example</groupId>
4 <artifactId>your-sdk</artifactId>
5 <version>1.0.0</version>
6 <packaging>jar</packaging>
7
8 <name>Your SDK</name>
9 <description>SDK for Your API</description>
10 <url>https://github.com/your-org/your-sdk</url>
11
12 <!-- License -->
13 <licenses>
14 <license>
15 <name>MIT License</name>
16 <url>https://opensource.org/licenses/MIT</url>
17 </license>
18 </licenses>
19
20 <!-- Developers -->
21 <developers>
22 <developer>
23 <name>Your Name</name>
24 <email>your@email.com</email>
25 <organization>Your Organization</organization>
26 </developer>
27 </developers>
28
29 <!-- SCM -->
30 <scm>
31 <connection>scm:git:git://github.com/your-org/your-sdk.git</connection>
32 <developerConnection>scm:git:ssh://github.com/your-org/your-sdk.git</developerConnection>
33 <url>https://github.com/your-org/your-sdk</url>
34 </scm>
35
36 <build>
37 <plugins>
38 <!-- Maven Source Plugin -->
39 <plugin>
40 <groupId>org.apache.maven.plugins</groupId>
41 <artifactId>maven-source-plugin</artifactId>
42 <version>3.3.1</version>
43 <executions>
44 <execution>
45 <id>attach-sources</id>
46 <goals>
47 <goal>jar-no-fork</goal>
48 </goals>
49 </execution>
50 </executions>
51 </plugin>
52
53 <!-- Maven Javadoc Plugin -->
54 <plugin>
55 <groupId>org.apache.maven.plugins</groupId>
56 <artifactId>maven-javadoc-plugin</artifactId>
57 <version>3.6.3</version>
58 <executions>
59 <execution>
60 <id>attach-javadocs</id>
61 <goals>
62 <goal>jar</goal>
63 </goals>
64 </execution>
65 </executions>
66 </plugin>
67
68 <!-- Maven GPG Plugin -->
69 <plugin>
70 <groupId>org.apache.maven.plugins</groupId>
71 <artifactId>maven-gpg-plugin</artifactId>
72 <version>3.2.7</version>
73 <executions>
74 <execution>
75 <id>sign-artifacts</id>
76 <phase>verify</phase>
77 <goals>
78 <goal>sign</goal>
79 </goals>
80 </execution>
81 </executions>
82 </plugin>
83
84 <!-- Central Publishing Maven Plugin -->
85 <plugin>
86 <groupId>org.sonatype.central</groupId>
87 <artifactId>central-publishing-maven-plugin</artifactId>
88 <version>0.6.0</version>
89 <extensions>true</extensions>
90 <configuration>
91 <publishingServerId>central</publishingServerId>
92 <autoPublish>true</autoPublish>
93 </configuration>
94 </plugin>
95 </plugins>
96 </build>
97</project>

Publish your Kotlin SDK to Maven Central

  1. Deploy to Maven Central.

    $mvn clean deploy

    With autoPublish set to true, artifacts are automatically published after validation. If set to false, you can manually publish from the Central Portal UI at central.sonatype.com.

  2. Verify the publication. After deployment, verify that your artifacts are available in the staging repository on the Central Portal, for example, https://repo1.maven.org/maven2/com/example/your-sdk/. Once verified, they’re released to Maven Central.

Publish updates

To publish updates to your SDK, do the following:

$# Update version in pom.xml
$mvn versions:set -DnewVersion=1.0.1
$mvn versions:commit
$
$# Deploy
$mvn clean deploy

Best practices for publishing Kotlin SDKs

Use the following best practices when publishing your Kotlin SDK to Maven Central:

  • Use semantic versioning.
  • Sign all artifacts with GPG.
  • Include source and Javadoc JARs.
  • Provide comprehensive documentation.
  • Tag releases in Git.
  • Consider using the Maven Release Plugin for automated releases.