PolyglotCode Published, but…

OSD600 (20 Part Series)

1 Open Source Development
2 My First Code Review
16 more parts…
3 First Interaction With Open Source
4 Learn New Things Everyday: First Pull Request
5 Merge TIME!
6 Continuous Contribution
7 Enhancing Code Quality Through Refactoring
8 First Hacktoberfest Experience
9 Hard Times
10 Take Smaller Tasks
11 Last Contribution For Hacktoberfest
12 Bye Bye Hacktoberfest
13 Contribution Instructions: Formate Code and Linting
14 Testing
15 CI GitHub Action Workflow
16 Open-Source Development is Amazing!
17 PolyglotCode Published, but…
18 OSD Final Chapter: Part 1
19 OSD Final Chapter: Part 2
20 OSD Final Chapter: Part 3

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.

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 😀.

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


OSD600 (20 Part Series)

1 Open Source Development
2 My First Code Review
16 more parts…
3 First Interaction With Open Source
4 Learn New Things Everyday: First Pull Request
5 Merge TIME!
6 Continuous Contribution
7 Enhancing Code Quality Through Refactoring
8 First Hacktoberfest Experience
9 Hard Times
10 Take Smaller Tasks
11 Last Contribution For Hacktoberfest
12 Bye Bye Hacktoberfest
13 Contribution Instructions: Formate Code and Linting
14 Testing
15 CI GitHub Action Workflow
16 Open-Source Development is Amazing!
17 PolyglotCode Published, but…
18 OSD Final Chapter: Part 1
19 OSD Final Chapter: Part 2
20 OSD Final Chapter: Part 3

原文链接:PolyglotCode Published, but…

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容