preface
This article documents how to publish a project to a public repository without a private Maven repository. In case of network, use Maven coordinates to obtain.
The body of the
Sonatype profile
Sonatype uses Nexus to provide hosting services for open source projects. It allows you to publish snapshots or stable releases to Maven’s central repository. We simply register a Sonatype JIRA account, create a JIRA ticket, and configure the POM file a little.
steps
1. Set up an account
The password must be more than 12 characters long and contain at least one uppercase character, one lowercase character, one special character, and at least three different characters (character, number, symbol). It contains uppercase letters, lowercase characters, symbols, and numbers, and contains more than 12 digits. So the password is something like Ff123456789/.
2. To create an issue
Once you have logged in successfully, open this link
Summary can be the name of the project
Description Describes the project
GroupId fill in IO. Github. PRPC (change to yours)
The Project URL and SCM URL can be used to access the Github Project.
Figure example:
After clicking “Create”, an issue will be launched and the page will automatically jump to a new page, as shown in the picture:
As you can see, the state here is OPEN. This state is actually waiting for review, and it may go through several state changes until it becomes RESOLVED. Note: The timing of this audit is uncertain.
We need to pay attention to changes in the audit status, generally changes will add new comments below, if we need to do something to follow the instructions.
3. Install encryption software
It is used to encrypt and sign files to be uploaded. The download address for Windows is GPG. The download is slow. If necessary, you can download it from a third-party source.
After installation, run the GPG –gen-key command on the command line to generate your own public key. The default configuration can be used except name, email address and remarks. Finally, you need to fill in a passphase (a number can be used for example: 62107872006), which will be used later in the MVN Release signature.
Finally, the console will display the following screen:
When we hit ok, because this encryption software actually has an interface. It will automatically import for us, and the next page will look like this:
We need to right click on this record and choose Publish on the server. It may prompt us to generate a revocation certificate file. Generally speaking, it is difficult for us to encounter the situation that the certificate needs to be revocation, so we choose ignore.
The above screen appears after success.
4. Modify the project
Modified pom
<! -- Configuration for maven central repository -->
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.3</version>
<extensions>true</extensions>
<configuration>
<serverId>oss</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<failOnError>false</failOnError>
<doclint>none</doclint>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>oss</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>oss</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>
</profiles>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<! -- Change here -->
<scm>
<url>https://github.com/pleuvoir/plugins-support</url>
<connection>scm:git:https://github.com/pleuvoir/prpc.git</connection>
<developerConnection>scm:git:https://github.com/pleuvoir/prpc.git</developerConnection>
<tag>v${project.version}</tag>
</scm>
<! -- Change here -->
<developers>
<developer>
<name>pleuvoir</name>
<email>[email protected]</email>
<url>https://pleuvoir.github.io</url>
</developer>
</developers>
Copy the code
Modify the maven setting. The XML
<! -- Sonatype account -->
<settings>
<servers>
<server>
<id>oss</id>
<username>Sonatype account</username>
<password>Sonatype password</password>
</server>
</servers>
</settings>
<! -- Configure GPG signature -->
<settings>
<profiles>
<profile>
<id>oss</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg2</gpg.executable>
<gpg.passphrase>Change the_pass_phrase as mentioned in the previous step</gpg.passphrase>
</properties>
</profile>
</profiles>
</settings>
Copy the code
5. Release
mvn clean deploy -DskipTests -P release
Or use the IDEA editor to select and publish.
Search project
Search io.github. PRPC to find the uploaded project information.
After the language
This article has documented how to publish open source projects to Sonatype, and hopefully it will help.