Maven central Repository Jar package submission guide
This article describes the process of uploading jars to Maven’s central repository. The project in this article is based on Github and uses the MAC environment (the configuration of Maven and JDK is not part of this article).
1. Apply for a Sonatype account
First we need to apply for an account, address is: issues.sonatype.org/secure/Sign…
Remember the username + password for this account, which will be used in the subsequent Maven setting.xml configuration file
After you have applied for an account, click on the New button (create if so) and submit an issue
- Project: Selection
Community Support - Open Source Project Repository Hosting (OSSRH)
- Question type: Select
New Project
- Summary: Project description
- Description: Project description
- GroupId: Note that for Github projects, the prefix is
com.github
, followed by your account name, like mine isliuyueyi
, so my groupId iscom.github.liuyueyi
If you do not meet this rule, you will not pass the subsequent audit Project URL
: Project address, fill in the corresponding Github connectionGithub.com/liuyueyi/qu…SCM URL
: Basically the same as above, except for one more.git
Basically what needs to be configured is shown below, and finally click New
Once submitted above, it is ready for review
2. Installed GPG
You need to use GPG to sign the JAR package when uploading it. The following describes the MAC installation process
Recommended use
A MacOS installation can be done with Homebrew
brew install gpg
Copy the code
An alternative to
But my MAC system is relatively old, using the above way to install failure, direct throw exception, according to the search results, do not upgrade the system seems to have no good solution
The following is the way of installation package. In principle, it is recommended to download the installation package from the official website. Still because of the version problem, I cannot install the latest one, so I found a historical download website. Although I use it myself)
If necessary, you can jump: sourceforge.net/p/gpgosx/do…
I chose 2.2.12. After the installation is complete, you can check the readme file to see the specific installation path
/usr/local/gnupg-2.2/bin = /usr/local/gnupg-2.2/bin = /usr/local/gnupg-2.2/bin = /usr/local/gnupg-2.2/bin = /usr/local/gnupg-2.2/bin
vim ~/.bash_profile
# add a new path
PATH=$PATH:/usr/local/ gnupg - 2.2 / binsource ~/.bash_profile
Copy the code
Key generation and publishing
Once installed, set up our own keys
Generate a key pair
Enter username + email, please remember this password, will be used when uploading jar package later
gpg --gen-key
Copy the code
Viewing a local Key
After the generation is complete, view the local key
gpg --list-keys
Copy the code
This is our public key ID, which we then upload to the key server
Upload the public keyGPG -- keyserver hkp://keyserver.ubuntu.com: 11371 - send - keys public key IDCheck whether the public key has been uploadedGPG -- keyserver hkp://keyserver.ubuntu.com: 11371 - recv - keys public key IDCopy the code
3. The maven configurations
Next, we need to set up our Maven configuration file setting.xml to fill in our user information
vim ~/.m2/setting.xml
Copy the code
Add the account information obtained in step 1 (username + password is the account password obtained in step 1).
# Add account information<servers>
<server>
<id>ossrh</id>
<username>user</username>
<password>password</password>
</server>
</servers>
Copy the code
4. Project configuration
The previous steps are environment-specific, so it’s time to configure the necessary information in our actual project, using github.com/liuyueyi/qu… Is used as an example
<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>com.github.liuyueyi</groupId>
<artifactId>quick-chinese-transfer</artifactId>
<packaging>pom</packaging>
<version>0.1</version>
<modules>
<module>transfer-core</module>
</modules>
<name>quick-chinese-transfer</name>
<description>
A Java library supporting conversion between Simplified-Chinese, Traditional-Chinese
</description>
<url>https://github.com/liuyueyi/quick-chinese-transfer</url>
<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>
<issueManagement>
<system>github</system>
<url>https://github.com/liuyueyi/quick-chinese-transfer/issues</url>
</issueManagement>
<scm>
<connection>scm:git:https://github.com/liuyueyi/quick-chinese-transfer.git</connection>
<developerConnection>scm:git:https://github.com/liuyueyi/quick-chinese-transfer.git</developerConnection>
<url>https://github.com/liuyueyi/quick-chinese-transfer</url>
</scm>
<developers>
<developer>
<name>YiHui</name>
<email>[email protected]</email>
<url>http://blog.hhui.top</url>
</developer>
</developers>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<mavenExecutorId>forked-path</mavenExecutorId>
<useReleaseProfile>false</useReleaseProfile>
<arguments>-Psonatype-oss-release</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.1.0</version>
<inherited>true</inherited>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<excludeResources>true</excludeResources>
<useDefaultExcludes>true</useDefaultExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<inherited>true</inherited>
<executions>
<execution>
<id>bundle-sources</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<maxmemory>1024</maxmemory>
<encoding>UTF-8</encoding>
<show>protected</show>
<notree>true</notree>
<! -- Avoid running into Java 8's very restrictive doclint issues -->
<failOnError>false</failOnError>
<doclint>none</doclint>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
<check/>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
<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>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<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>
</plugins>
</build>
</profile>
</profiles>
</project>
Copy the code
Above is a complete configuration information, among which, a few very core points
groupId
: Please note that it is consistent with the applicationplugins
: We upload jar package, need to include doc and source code, somaven-source-plugin
+maven-javadoc-plugin
essentialmaven-gpg-plugin
: signed plug-in, necessary
In my actual project development process, I encountered a problem here. Maven-gpg-plugin cannot be downloaded and has been marked in red. If you encounter this problem, you can direct the download
mvn dependency:get -DrepoUrl=http://repo.maven.apache.org/maven2/ . - Dartifact = org, apache maven plugins: maven GPG -- plugin: 1.6Copy the code
In addition, you can update dependencies via IDEA Setup -> Maven -> Repositories
After the above configuration is complete, it is packaged upload, directly use the following command can be
mvn clean deploy -DskipTests=true -P release
Copy the code
During the execution of this command, a popup window for entering the GPG password will pop up. Enter the password you filled in when generating the GPG key in the second step
Once the jar package has been uploaded, it can be seen at oss.sonatype.org/
Pay attention to
When you have reviewed the issues submitted in the first step, you will receive an email notifying you that you are ready to publish the corresponding JAR package. You can also see the following reply in the Issues section
- You will be prompted to create an empty repository on Github for permission verification
- Once created, change the issue state
- You can upload the JAR package
- Then perform the jar package publishing above
5. Release the JAR package
Next go to oss.sonatype.org/#stagingRep… Manage the JAR packages we upload
- Click on the
Staging Repositories
- Select the JAR we want to publish
- Click on the close
After clicking close, if everything is ok, then after a while, you will find that the Release button is ready to click, and then click Release to publish
If all goes well, we will receive an email telling us that we have published successfully and are ready to synchronize the JAR package
Then wait ten minutes and you can rely directly on importing jar packages
<dependency>
<groupId>com.github.liuyueyi</groupId>
<artifactId>quick-transfer-core</artifactId>
<version>0.1</version>
</dependency>
Copy the code
Pay attention to
As for the above release, it may not go so smoothly. For example, I met several problems before. Click the Activites of the selected package to check the cause of failure
The reasons for the above problems mainly lies in the poM configuration of the project, which leads to the package uploaded without signature, source and Java-doc
Secondly, I also encountered a problem that the GPG key was not found. This may be because the key we uploaded has not been synchronized, so there is a delay. Just try again
5. Summary
Although there are many online tutorials, but in the actual operation, there will always be some problems that others do not encounter, of course, if there is no problem, that is of course the most fortunate thing; This article is mainly to record the whole process of the central warehouse of JAR package uploading, and make a summary, which is also convenient for follow-up reference. Of course, it is also good if it can be helpful to other partners
At the time of this writing, the uploaded JAR packages are searchable in the central repository
Reference documentation
- Publish projects to potholes trodden in Maven’s central repository
- How to submit a project to Maven’s central repository
II. The other
1. A gray Blog:liuyueyi.github.io/hexblog
A gray personal blog, recording all the study and work in the blog, welcome everyone to go to stroll
2. Statement
As far as the letter is not as good, the above content is purely one’s opinion, due to the limited personal ability, it is inevitable that there are omissions and mistakes, if you find bugs or have better suggestions, welcome criticism and correction, don’t hesitate to appreciate
- Micro Blog address: Small Gray Blog
- Wechat official account: One Grey Blog