Push Java project to Maven central warehouse practice

The latest open source project Swagger Kubernetes has been written. Considering the successful release to Maven's central warehouse, it is universal in the world. In the process of Maven's pull, there is no problem that Jar package is not available for download. Due to the first time the project was submitted to Maven central warehouse, the online knowledge was uneven until at last a lot of holes were encountered. Here is a record of the practice process.

1, Push project to Github

Create a new project warehouse on Github and push the code to be sent to Maven central warehouse to Github. There is a lot of information in this regard, but there is no more description here.

2, Sign up for a Sonatype account

Enter https://issues.sonatype.org/secure/Dashboard.jspa Sign up for JIRA account and complete personal information as prompted.

3, Log in to Sonatype to create a work order

Login https://issues.sonatype.org/secure/Dashboard.jspa , click the Create button to create a new issues job

The content is as follows. Fill in the required part and wait for approval.

4, Confirm domain name

Wait for a while and you will receive an email with the following content:

[ https://issues.sonatype.org/browse/OSSRH-48958?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Central OSSRH Updated OSSRH-48958:
------------------------------
//Status: Waiting for Response (original value: open)

Do you own the domain mydlq.club? If so, please verify ownership via one of the following methods:
* Add a TXT record to your DNS referencing this JIRA ticket: OSSRH-48958 (Fastest)
* Setup a redirect to your Github page (if it does not already exist)

If you do not own this domain, please read:
http://central.sonatype.org/pages/choosing-your-coordinates.html
You may also choose a groupId that reflects your project hosting, in this case, something like io.github.my-dlq or com.github.my-dlq

Swagger Kubernetes is a program for document aggregation of Swagger standardized service apis in a Kubernetes cluster.
----------------------------------------------------------------------------------------------------------------------

//Key words: OSSRH-48958
URL: https://issues.sonatype.org/browse/OSSRH-48958
//Project: community support - open source project repository housing
//Question type: New Project
//Reported by: mydlq
//Handled by: Joel Orlina
//Priority: important

Swagger Kubernetes is a program for document aggregation of Swagger standardized service apis in a Kubernetes cluster. Service discovery under a Namespace of Kubernetes can be automatically performed. The interface of the Swagger API specification will be integrated and filtered. The service will be delegated to the service by zuul reverse proxy, and the Swagger API information will be aggregated and displayed by the Swagger UI.

It means to ask whether the domain name you set for GroupId is owned by yourself. If so, you need to prove two methods

  • 1. Set github page as domain name.
  • 2. Add a record of type Txt to DNS resolution of domain name.

Because I have my own domain name, I set up the second method to add NDS resolution record. Here, I add the record as OSSRH-48958, the type as TxT, and the value as https://issues.sonatype.org/browse/OSSRH-48958 A parsing record information of.

Then open the address mentioned in the email https://issues.sonatype.org/browse/OSSRH-48958 Enter the issues, reply that you own the domain name, and set DNS resolution.

5, Configure GPG

1. Download GPG

Open https://www.gpg4win.org/ Download the GPG and install it step by step.

After the installation, you will see that there are multiple Kleopatra icons on the desktop. This program is the front-end program of GnuPG. Here we will open it.

2. Configure key pair

After opening Kleopatra, click new key pair

Enter name and email

Finally, confirm to create a new one

In the process, you need to enter a password of more than 8 digits by yourself. Please remember the password, which needs to be used later. The following information will be prompted when the input is complete.

3. Upload public key to GPS key servers

Open the command prompt window and enter the following command to send the certificate to the remote server

gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys  243EFB60D8F930B391CA194EA40663B00BDC6CA1

6, Configuration items

To send the project to Maven central warehouse, you need to set up some settings for the project to meet the release criteria.

1. Configure Strings.xml

Configure the settings.xml file in the conf folder of the maven directory, set a server, and add the account and password of JIRA.

<servers>
   <server>
      <id>ossrh</id>
      <username>JIRA Account number</username>
      <password>JIRA Password</password>
   </server>
</servers>

2. Configure Pom.xml

Pom.xml configures some necessary information, such as Maven document plug-in, packaging plug-in, GPG validation plug-in, etc., as follows:

You can view my project's GitHub address: Maven sample project , the pom parameter can be modified as required. By the way, click Start star, Thanks.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>club.mydlq</groupId>
    <artifactId>swagger-kubernetes</artifactId>
    <version>2.1.0</version>
    <packaging>jar</packaging>

    <name>swagger-kubernetes</name>
    <url>https://github.com/my-dlq/swagger-kubernetes</url>
    <description>swagger api doc for kubernetes discovery.</description>

    <!--licenses information-->
    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <!--scm information-->
    <scm>
        <url>http://mydlq.club</url>
        <connection>scm:git:https://github.com/my-dlq/swagger-kubernetes.git</connection>
        <developerConnection>scm:git:https://github.com/my-dlq/swagger-kubernetes.git</developerConnection>
    </scm>

    <!--Publisher information-->
    <developers>
        <developer>
            <name>mydlq</name>
            <email>mynamedlq@163.com</email>
            <organization>http://mydlq.club</organization>
            <organizationUrl>http://mydlq.club</organizationUrl>
        </developer>
    </developers>

    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.1.0.RELEASE<</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- doc plugin,Maven API Document generation plug in -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- resources plugin,Maven Resource plug-in -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- compiler plugin,Maven Compiler plug-in -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <showWarnings>true</showWarnings>
                </configuration>
            </plugin>
            <!-- gpg plugin,For signature authentication -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!--staging puglin,Used to automate the publish phase(Manual Free)-->
             <plugin>
                <groupId>org.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
                <version>1.6.7</version>
                <extensions>true</extensions>
                <configuration>
                    <serverId>ossrh</serverId>
                    <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                    <autoReleaseAfterClose>true</autoReleaseAfterClose>
                </configuration>
            </plugin>
            <!-- release plugin,For publishing to release Warehouse deployment plug-in -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.4.2</version>
            </plugin>
        </plugins>
    </build>

    <!-- Introduce here Settings.xml User name and password set in -->
    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>

</project>

3. Set encoding

If Maven compiles doc due to coding errors, you can set the variable Java tool options in the environment variable with a value of UTF-8 to change the coding mode.

  • JAVA_TOOL_OPTIONS
  • -Dfile.encoding=UTF-8

7, Send project to Maven central warehouse

1. Log in to Nexus Repositories Manager

It is required to log in to Nexus Repositories before publishing, so log in to Nexus Repositories in advance before publishing

Login https://oss.sonatype.org The user name and password are the user name and password of JIRA.

2. Publish project

Execute the command of maven, deploy the project to Maven warehouse, and enter the GPG password set before in the process. Just enter it.

$ mvn clean deploy

3. View publishing process

Go back to Nexus Repositories Manager, select Staging Repositories, and find the Jar information you submitted according to the release time. Then check the execution information in Actives. Note that the execution and deployment process is now popular and handed over to Maven's auto deployment plug-in for execution. Some old methods on the Internet are to enter here for manual execution, which is not recommended because it is very easy to have problems in deployment.

Note: as can be seen during Maven's release, if the release has been completed, it may not be found in the staging library.

The normal deployment process should be: open phase > close phase > release phase. After the three phases are completed, they will be released to the central warehouse, and will be notified by email

[ https://issues.sonatype.org/browse/OSSRH-48958?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Central OSSRH Updated OSSRH-48958:
------------------------------

Central sync is activated for club.mydlq. After you successfully release, your component will be published to Central, typically within 10 minutes, though updates to search.maven.org can take up to two hours.

It means that the Release is successful, and the Jar information can be found in the central warehouse in about ten minutes or a few, but the update of search.maven.org may take two hours.

4. Reply in Issues completed Release

Submit the Issues address before opening, and the subsequent reply has been released

5. View your published projects

After successful publishing, you can enter https://search.maven.org If you don't find the Jar published by yourself, wait a few hours for this query.

Tags: Maven Kubernetes github Apache

Posted on Mon, 16 Mar 2020 22:00:44 -0700 by Coreyjames25