Giter Club home page Giter Club logo

maven-hello-world's Introduction

Maven Hello World

Getting started with Maven Release Plugin and Github Action

Links

Login to your sonatype account to release the version

Type URL Description
Snapshot sonatype Sonatype Snapshot versions
Release maven Maven Release versions
Release central-sonatype Sonatype Release versions

Documentation

Secrets

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

Demo

How do you release a version?

Manually:
   1. Check the version in the pom.xml
      * 0.0.1-SNAPSHOT
   2. Go to Github action -> Run workflow
      * Release: 0.0.1
      * Snapshot: 0.0.2-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>com.chenspoul</groupId>
    <artifactId>maven-hello-world</artifactId>
    <version>0.0.1</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'

Local commands

Check your maven settings file ~/.m2/settings.xml:

    <server>
        <id>gpg.passphrase</id>
        <passphrase><PASSPHRASE_GPG></passphrase>
    </server>
    <server>
        <id>ossrh</id>
        <username><OSSRH_USERNAME></username>
        <password><OSSRH_TOKEN></password>
    </server>

According to publish-maven, you can do these as below.

Performing a Snapshot Deployment

Snapshot deployment are performed when your version ends in -SNAPSHOT . You do not need to fulfill the requirements when performing snapshot deployments and can simply run

mvn -B clean deploy

SNAPSHOT versions are not synchronized to the Central Repository. If you wish your users to consume your SNAPSHOT versions, they would need to add the snapshot repository to their Nexus Repository Manager, settings.xml, or pom.xml. Successfully deployed SNAPSHOT versions will be found in https://s01.oss.sonatype.org/content/repositories/snapshots/

Performing a Release Deployment

In order to perform a release deployment you have to edit your version in all your POM files to use release versions.

mvn versions:set -DnewVersion=1.2.3 versions:commit

Install to local repository ~/.m2/repository:

mvn clean install

Release to the staging repositorywith the release profile:

mvn clean deploy -P release

And then login to the staging repository https://s01.oss.sonatype.org/#stagingRepositories , release and drop the repository. Wait a few minutes and then you can find the release version in https://central.sonatype.com/artifact/com.chensoul/maven-hello-world/ or https://s01.oss.sonatype.org/service/local/repositories/releases/content/com/chensoul/maven-hello-world/ .

Manually Publish the site to github pages

Publish to github pages:

mvn clean site scm-publish:publish-scm

maven-hello-world's People

Contributors

chensoul avatar dependabot[bot] avatar github-actions[bot] avatar actions-user avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.