PolyglotCode Published, but...

amullagaliev

Amir Mullagaliev

Posted on November 25, 2024

PolyglotCode Published, but...

Table of Contents


Maven Central Repository

Maven Central Repository is the place where all Java developers publish their tools, code and projects. During last week I had to figure out how to push there my project - PolyglotCode. I started reading documentation on how to make my project accessible without forking it.

Let me quickly walk you through the steps I had to take before deploying the project.


Project Preparation

Prepare pom.xml

Add metadata: groupId, artifactId, version, name, license, and description.

In my case:

    <groupId>io.github.mulla028</groupId>
    <artifactId>PolyglotCode</artifactId>
    <version>1.0</version>
    <name>PolyglotCode</name>
    <description>Simple CLI Tool that translates your code in ANY programming language! Powered by AI.</description>
    <url>https://github.com/mulla028/PolyglotCode</url>
    <licenses>
        <license>
            <name>MIT License</name>
            <url>https://opensource.org/licenses/MIT</url>
            <distribution>repo</distribution>
        </license>
    </licenses>
Enter fullscreen mode Exit fullscreen mode

Another thing that you have to add in pom.xml is Deployment Target Configuration. Meta data <distrubutionManagement> which completes the separation of releases and snapshots.

     <distributionManagement>
        <repository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
Enter fullscreen mode Exit fullscreen mode

GPG (GNU Privacy Guard)

You have to install GPG to sign artifacts to verify their authenticity.

Install:

brew install gpg
Enter fullscreen mode Exit fullscreen mode

Create a Key Pair:

gpg --full-generate-key
Enter fullscreen mode Exit fullscreen mode

Continue Setting Up pom.xml

After you've generated a pair of keys for gpg, we set up profile and specifying short version of key:

    <profiles>
        <profile>
            <id>ossrh</id>
            <properties>
                <gpg.executable>gpg</gpg.executable>
                <gpg.keyname>8882786B85D55E84</gpg.keyname>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
    </profiles>
Enter fullscreen mode Exit fullscreen mode

Create settings.xml

After all the project preparations, you must create settings.xml inside of you Maven Configuration Directory.

  • For macOS/Linux the path is: ~/.m2/settings.xml
  • For Windows: C:\Program Files\Apache Software Foundation\maven\conf\settings.xml

The content of settings.xml looks like this:

<settings>
  <servers>
    <server>
        <id>ossrh</id>
        <username><your-username></username>
        <password><your-password></password>
    </server>
  </servers>
</settings>
Enter fullscreen mode Exit fullscreen mode

and you should generate in Maven Central Repository web-site, after signing in. They provide simple copy-paste code block for your settings.xml file, so it shouldn't cause problems.

Deployment

Last one thing that we are going to add in pom.xml is:

           <plugin>
                <groupId>org.sonatype.central</groupId>
                <artifactId>central-publishing-maven-plugin</artifactId>
                <version>0.6.0</version>
                <extensions>true</extensions>
                <configuration>
                    <publishingServerId>ossrh</publishingServerId>
                    <waitUntil>published</waitUntil>
                </configuration>
            </plugin>
Enter fullscreen mode Exit fullscreen mode

This will allow us to use deployment maven command.

You are almost done, next step requires simple terminal command:

mvn deploy
Enter fullscreen mode Exit fullscreen mode

Publish It

You have to go to the Maven Central Repository, and will see that you deployment is verifying, after some time, if everything goes as expected, the button Publish will appear.

Image description

How to Find Published Product

In Maven Central Repository you check your product by artifactId, in my case it's PolyglotCode. My project looks like this: Click me :D.

Note: There you will be able to find instructions on how to integrate your project into your project.

The Saddest Part

I wasn't able to find a way how to publish my tool as CLI tool, and was only able to publish it as a component for Maven, which you integrate, and use as a class...

To create a CLI tool next time I would use JS, TS, Rust, etc...

Conclusion

I was so excited to share with you my first ever published work. Unfortunately, it did go as I wasn't expecting :c


💖 💪 🙅 🚩
amullagaliev
Amir Mullagaliev

Posted on November 25, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

PolyglotCode Published, but...
opensource PolyglotCode Published, but...

November 25, 2024