Configure the environment
The installationjava
The environment
Link: https://pan.baidu.com/s/1o-wFA-m33JQs-sQJ-DgRaQ extraction code: ux7jCopy the code
Download to the server and unzip to the specified location
$ mkdir /usr/java
$tar xzf jdk-8u301-linux-x64.tar.gz -C /usr/java
$ vim /etc/profile
Copy the code
Write the following
Export JAVA_HOME = / usr/Java/jdk1.8.0 _301 export CLASSPATH = $JAVA_HOME/lib/tools. The jar: $JAVA_HOME/lib/dt. The jar: $JAVA_HOME/lib export PATH=$JAVA_HOME/bin:$PATHCopy the code
Save the Settings and exit the source /etc/profile command for the configuration file to take effect.
Verify that the installation is successful
$Java -version Java version "1.8.0_301" Java(TM) SE Runtime Environment (build 1.8.0_301-B09) Java HotSpot(TM) 64-bit Server VM (Build 25.301-B09, Mixed mode)Copy the code
If you see this, the installation is successful.
The installationmaven
$ mkdir /usr/mvn $ cd /usr/mvn $ wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz $tar ZXVF. - Apache maven - 3.8.1 - bin. Tar. Gz $vim/etc/profileCopy the code
Say the following
Export MAVEN_HOME = / usr/MVN/apache maven - 3.8.1 export PATH = $PATH: $MAVEN_HOME/binCopy the code
Save the Settings and exit the source /etc/profile command for the configuration file to take effect.
Verify that the installation is successful
$MVN -version Maven home: /usr/mvn/apache-maven-3.8.1 Java version: 1.8.0_301, Vendor: Oracle Corporation, Runtime: /usr/java/jdk1.8.0_301/ JRE Default locale: en_US, platform Encoding: UTF-8 OS name: "Linux ", version: "4.18.0-240.10.1. El8_3. X86_64," arch: "amd64," family: "Unix"Copy the code
Other tools
$ yum install git gpg -y
Copy the code
Skip this step if it is already installed
registeredsonatype
account
Click to register a new account.
Create a new one after loginissues
XXX Group Id: com.github. XXX Group Id: com.github. XXX Group Id: com.github
Create completed will jump to the link https://issues.sonatype.org/browse/OSSRH-xxxx, when you see the connection, you want to create a warehouse on your lot, to prove that you are the owner of the lot, The name of the warehouse is osSRH-XXXX in the connection.
Create the warehouse after the connection to https://github.com/yourgithubname/OSSRH-xxxx, and then leave a message to tell the administrator the warehouse under the posts you have created a name for OSSRH – XXXX warehouse, so can save he let you prove you are the owner of this account, Improve efficiency. After the administrator replies, you can upload the JAR package.
Here is the administrator’s reply. If you see this, you are done.
io.github.xxx has been prepared, now user(s) youname can: Publish snapshot and release artifacts to s01.oss.sonatype.org Have a look at this section of our official guide for deployment instructions: https://central.sonatype.org/publish/publish-guide/#deployment Depending on your build configuration, your first component(s) might be released automatically after a successful deployment. If that happens, you will see a comment on this ticket confirming that your artifact has synced to Maven Central. If you do not see this comment within an hour or two, you can follow the steps in this section of our guide: https://central.sonatype.org/publish/release/ ###### As part of our efforts to improve the security and quality posture of the open source supply chain, we plan to enable additional scanning of dependencies for security alerts soon. Since you're already hosting your source code in Github, you can get these insights today by enabling Sonatype Lift. Sonatype Lift is free forever on public repositories! Lift tells you about open source vulnerabilities during code review, and goes beyond open source to scan your code for both code quality and security issues, providing feedback right in your pull requests. More information can be found at https://links.sonatype.com/products/lift/github-integration ######Copy the code
Preparation before launch
Modify thepom
file
<groupId>io.github.xxxx</groupId>
<artifactId>xxxx</artifactId>
<version>1.0.0</version>
<name>xxx</name>
<url>xxxx</url>
<description>xxxxx</description>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<! -- Source -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<! -- Javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<! -- GPG mvn clean deploy -P release -Dgpg.passphrase=YourPassphase -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<licenses>
<license>
<name>MIT License</name>
<url>https://github.com/xxx/xxx/xxxxxx/master/LICENSE</url>
<distribution>repo,manual</distribution>
</license>
</licenses>
<developers>
<developer>
<name>xxx</name>
<email>xxxx</email>
<url>xxxx</url>
</developer>
</developers>
<scm>
<connection>scm:git:https://github.com/xxx/xxxx.git</connection>
<developerConnection>scm:git:https://github.com/xxxx/xxxx.git</developerConnection>
<url>https://github.com/xxxx/xxxxx</url>
<tag>0.0.1</tag>
</scm>
Copy the code
You only need to modify the content related to yourself, which is represented by XXXX in the article. Other contents do not need to be modified
The Group Id must be the same as that applied for
uploadgpg key
$ gpg generate-key
#Enter your username and email address as prompted, and then enter a password that you will use next
Copy the code
Sends the public key to the PGP key server
$ gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 6107DF0A8EE6A62EABFDD12914F722543E7D2C1E
Copy the code
Returns the result
GPG: upload key '14 f722543e7d2c1e to hkp://keyserver.ubuntu.com: 11371Copy the code
Verify that the upload is successful
$ gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys 6107DF0A8EE6A62EABFDD12914F722543E7D2C1E
Copy the code
Returns the result
GPG: key 14F722543E7D2C1E: houbb <[email protected]> Unchanged GPG: Total number of processes: 1 GPG: unchanged: 1Copy the code
setting.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd">
<servers>
<server>
<id>ossrh</id>
<username>Sonatype account</username>
<password>Sonatype password</password>
</server>
</servers>
<profiles>
<profile>
<id>ossrh</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg2</gpg.executable>
<gpg.passphrase>Password of the GPG public key</gpg.passphrase>
</properties>
</profile>
</profiles>
</settings>
Copy the code
Setting. XML file in MVN home directory conf folder or user directory
The uploader
Execute in the project root directory
$ mvn clean deploy
Copy the code
After a few moments, a window will appear. Enter the PASSWORD of GPG
If you see this, it’s been uploaded successfully.
Upload after successful login to the https://s01.oss.sonatype.org/ account is initially registered sonatype account.
Once you’re logged in, click Staging Repositories and you’ll see this page. Select the record and click Close. Once you’re done, click Release.
At this stage, you are done. Wait a moment and you can see the uploaded package here
For example, the Group Id is io.github. XXX
ArtifactId is tool
Version 1.0.0,
Check the address is https://repo.maven.apache.org/maven2/io/github/xxx/tool/1.0.0
If the above connection can be found, it is already available for use in the project. The timing of the synchronization to the central warehouse is uncertain.
Post a successful reply to the post, tell the administrator that the post was successful.
Problems encountered
-
When executing MVN deploy, there is always a 401 error returned. We tried all kinds of methods but could not solve the problem. We just registered a new account.
-
The repository location has changed and most of the articles on the web are now old and new
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
Copy the code
The latest configuration information is provided in the official document. If you encounter problems, consult the official document first
- in
centos
Publishing times error
Failed to execute goal org, apache maven. Plugins: maven GPG -- plugin: 1.6: sign
The solution