Skip to content

naturalett/maven-hello-world

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Release

Getting started with Maven Release

Links

Login to your sonatype account to release the version

Type URL Description
Snapshot sonatype Snapshot versions
Release sonatype Release versions
Release central-sonatype Release versions

Documentation

Secrets

  • MAVEN_GPG_PRIVATE_KEY - Take it from the private.gpg
  • OSSRH_USERNAME - Created here
  • OSSRH_TOKEN - Created here
  • MAVEN_GPG_PASSPHRASE - Create here
    • This passphrase and your private key are all that is needed to sign artifacts with your signature.
  • TOKEN - Github token

Demo

How do you release a version?

Manually:
   1. Check the version in the pom.xml
      * 0.2.26-SNAPSHOT
   2. Go to Github action -> Run workflow
      * Release: 0.2.26
      * Snapshot: 0.2.27-SNAPSHOT

Automatically:
Push to Github will create a release and a snapshot but it won't publish the release.
Snapshot will be available through here

<dependency>
    <groupId>io.github.naturalett</groupId>
    <artifactId>my-app</artifactId>
    <version>1.0.3</version>
</dependency>

Maven in 5 Minutes

Follow after the documentation here to start your first maven.

Expend your ./src/main/java/com/mycompany/app/App.java with:

package com.mycompany.app;

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;

public class App 
{
    public static void main( String[] args ) throws IOException {

        HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
        server.createContext("/", new MyHandler());
        server.setExecutor(null); // creates a default executor
        server.start();

    }

    static class MyHandler implements HttpHandler {
        @Override
        public void handle(HttpExchange t) throws IOException {
            String response = "<h1> Hello World! </h1>";
            t.sendResponseHeaders(200, response.length());
            OutputStream os = t.getResponseBody();
            os.write(response.getBytes());
            os.close();
        }
    }
}

GPG

After generating gpg key following by here

gpg --gen-key

You can list the local key that you created:

gpg --list-secret-keys --keyid-format=long

Then you can export the private key to your local machine in order to upload it later to Github secret:

gpg --armor --export-secret-keys <YOUR_KEY> > private.gpg
  • YOUR_KEY='long number'...B720

Local commands

Release + Snapshot:

mvn --batch-mode release:clean release:prepare release:perform -Dusername=naturalett -Dpassword=<GITHUB_TOKEN> -s settings.xml -X

Bump version:

mvn --batch-mode build-helper:parse-version versions:set -DnewVersion=0.2.0-SNAPSHOT versions:commit -Dusername=naturalett -Dpassword=<GITHUB_TOKEN> -s settings.xml -X

GPG to sign:

mvn -X -B clean javadoc:jar source:jar deploy -Dgpg.passphrase="<PASSPHRASE_GPG>" -Pci-cd -s settings.xml

Authors