[JAVA] Verfahren zum Veröffentlichen im Maven Central Repository

Ich habe meine Bibliothek im Maven Central Repository veröffentlicht. Früher habe ich mich auf das offizielle Verfahren bezogen, aber an einigen Stellen ist ein Fehler aufgetreten, daher werde ich das Verfahren hier schreiben.

Referenz

Erstellen Sie ein Sonatyp-JIRA-Konto

https://issues.sonatype.org/secure/Signup!default.jspa

Neues Projekt erstellen Registrieren Sie ein neues Problem

https://issues.sonatype.org/secure/CreateIssue.jspa?issuetype=21&pid=10134

Wenn die Gruppen-ID eine eigene Domäne ist, scheint sie den Besitz der Domäne zu authentifizieren. In meinem Fall habe ich com.github.pandafw eingegeben und es wurde sofort genehmigt.

Installieren Sie GNU PG

Um JAR-Dateien usw. in Maven Central zu veröffentlichen, ist ein GPG-Zeichen erforderlich. Installieren Sie daher GNU PG.

https://www.gnupg.org/download/ Da es sich um einen Windows-PC handelt, https://www.gnupg.org/ftp/gcrypt/binary/gnupg-w32-2.2.12_20181214.exe Ich habe installiert.

C:\Develop\Tools\gnupg\bin>gpg --version
gpg (GnuPG) 2.2.12
libgcrypt 1.8.4
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: C:/Users/Ryoma/AppData/Roaming/gnupg
Supported algorithms:
Pubkey: RSA, ELG, DSA, ECDH, ECDSA, EDDSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
        CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2

Erstellen Sie einen Schlüssel mit GPU PG

C:\Develop\Tools\gnupg\bin>gpg --full-gen-key
gpg (GnuPG) 2.2.12; Copyright (C) 2018 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)
Requested keysize is 2048 bits
Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) y
GnuPG needs to construct a user ID to identify your key.
Real name: Ryoma Kimura
Email address: [email protected]
Comment:
You selected this USER-ID:
    "Ryoma Kimura <[email protected]>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: C:/Users/Ryoma/AppData/Roaming/gnupg/trustdb.gpg: trustdb created
gpg: key 27835B3BD2A2061F marked as ultimately trusted
gpg: directory 'C:/Users/Ryoma/AppData/Roaming/gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as 'C:/Users/Ryoma/AppData/Roaming/gnupg/openpgp-revocs.d\5694AA563793429557F1727835B3BD2A223A.rev'
public and secret key created and signed.
pub   rsa2048 2019-02-11 [SC]
      5694AA563793429557F1727835B3BD2A223A
uid                      Ryoma Kimura <[email protected]>
sub   rsa2048 2019-02-11 [E]

Geben Sie die Passphrase ein. image.png

Veröffentlichungsschlüssel auf GPU PG

C:\Develop\Tools\gnupg\bin>gpg –-send-keys [KEY_ID]

Geben Sie für [KEY ID] die im vorherigen Schritt generierte 5694AA563793429557F1727835B3BD2A223A ein.

Fügen Sie pom.xml Distributionsmanagement hinzu

<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>

Fügen Sie ein gpg-Zeichen hinzu und stellen Sie das Plugin in pom.xml bereit

<!-- sonatype release -->
<plugin>
	<groupId>org.sonatype.plugins</groupId>
	<artifactId>nexus-staging-maven-plugin</artifactId>
	<version>1.6.8</version>
	<extensions>true</extensions>
	<configuration>
		<serverId>ossrh</serverId>
		<nexusUrl>https://oss.sonatype.org/</nexusUrl>
		<autoReleaseAfterClose>true</autoReleaseAfterClose>
	</configuration>
</plugin>

<!-- gpg sign -->
<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>

Fügen Sie der pom.xml scm-Informationen hinzu.

<scm>
	<connection>scm:git:https://github.com/pandafw/panda.git</connection>
	<developerConnection>scm:git:https://github.com/pandafw/panda.git</developerConnection>
	<url>https://github.com/pandafw/panda</url>
</scm>

Fügen Sie jomadoc und das Plugin für Anhängequellen zu pom.xml hinzu.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  <version>2.2.1</version>
  <executions>
	<execution>
	  <id>attach-sources</id>
	  <goals>
		<goal>jar-no-fork</goal>
	  </goals>
	</execution>
  </executions>
</plugin>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-javadoc-plugin</artifactId>
  <version>2.9.1</version>
  <executions>
	<execution>
	  <id>attach-javadocs</id>
	  <goals>
		<goal>jar</goal>
	  </goals>
	</execution>
  </executions>
</plugin>

Fügen Sie Ossrh-Serverinformationen zu Maven settings.xml hinzu.

Der Standardpfad für settings.xml lautet C: \ Users \ Ryoma \ .m2 \ settings.xml

<servers>
	<server>
		<id>ossrh</id>
		<username>your-jira-id</username>
		<password>your-jira-password</password>
	</server>
</servers>

Fügen Sie der Maven settings.xml die gpg-Passphrase hinzu.

<profiles>
	<profile>
		<id>ossrh</id>
		<activation>
			<activeByDefault>true</activeByDefault>
		</activation>
		<properties>
			<gpg.executable>gpg</gpg.executable>
			<gpg.passphrase>[your_gpg_passphrase]</gpg.passphrase>
		</properties>
	</profile>
</profiles>

Veröffentlichung

mvn clean deploy

Melden Sie sich bei ossrh an und überprüfen Sie die Informationen zu den Staging-Repositorys.

https://oss.sonatype.org/

image.png

Wenn keine Probleme auftreten, drücken Sie zum Schließen die Taste [Schließen]. Während des Abschlussvorgangs werden verschiedene Überprüfungen durchgeführt. Wenn die Prüfung nicht bestanden wird, wird eine Fehlermarkierung hinzugefügt, sodass Sie die Fehlerinformationen auf der Registerkarte [Aktivität] überprüfen können. In meinem Fall gab es aufgrund eines Einstellungsfehlers einen Fehler, dass das GPG-Zeichen nicht ausgeführt wurde, oder einen Fehler, dass der GPG-Schlüssel nicht vom Server abgerufen werden konnte. Löschen Sie daher das Repository mit dem Fehler, korrigieren Sie die Einstellung und geben Sie es mit mvn clean deploy erneut frei. Machen.

Am Ende loslassen.

Sobald Sie das hochgeladene Repository ordnungsgemäß geschlossen haben, können Sie es freigeben, indem Sie auf die Schaltfläche [Freigeben] klicken. Ungefähr einige Stunden später unter https://search.maven.org Es wird sich in widerspiegeln.

Recommended Posts

Verfahren zum Veröffentlichen im Maven Central Repository
Ein neuer Ingenieur hat seine eigene Bibliothek im Maven Central Repository veröffentlicht
So erstellen Sie ein Maven-Repository für 2020
Lokaler Cache des Maven-Repositorys
Stellen Sie Maven das Tomcat-Projekt vor
Serverless (Walter + GitHook) registriert Ergebnisse automatisch im Nexus Repository (Maven Central).