如果您想知道如何将您的工件发布到 Maven 中心,那么这个分步指南就是为您准备的。小心,你需要 Github。
必备步骤
步骤1: 确保已经安装了 JDK、 Maven、 Github 等。
步骤2: 创建一个 Github 帐户,如果你还没有的话。
步骤3: 创建一个新的 Github 存储库。
步骤4: 添加一个新的 SSH 密钥到您的 Github 帐户
步骤5: 将代码推送到 Github。
步骤6: 注册一个 Sonatype Jira 帐户。
步骤7: 为新的项目托管创建一个 Jira 问题。点击这里查看示例请求。
步骤8: 安装 GNU PG。在操作系统中安装并验证如下:
C:\Users\Nadeem>gpg --version
gpg (GnuPG) 2.1.15
libgcrypt 1.7.3
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
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/Nadeem/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
C:\Users\Nadeem>
步骤9: 生成密钥对。
C:\Users\Nadeem>gpg --full-gen-key
gpg (GnuPG) 2.1.15; Copyright (C) 2016 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.
gpg: keybox 'C:/Users/Nadeem/AppData/Roaming/gnupg/pubring.kbx' created
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
= key expires in n days
w = key expires in n weeks
m = key expires in n months
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: Nadeem Mohammad
Email address: coolmind182006@gmail.com
Comment:
You selected this USER-ID:
"Nadeem Mohammad "
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/Nadeem/AppData/Roaming/gnupg/trustdb.gpg: trustdb created
gpg: key 27835B3BD2A2061F marked as ultimately trusted
gpg: directory 'C:/Users/Nadeem/AppData/Roaming/gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as 'C:/Users/Nadeem/AppData/Roaming/gnupg/openpgp-revocs.d\5694AA563793429557F1727835B3BD2A223A.rev'
public and secret key created and signed.
pub rsa2048 2016-08-29 [SC]
5694AA563793429557F1727835B3BD2A223A
uid Nadeem Mohammad
sub rsa2048 2016-08-29 [E]
C:\Users\Nadeem>
步骤10: 输入密码短语。
步骤1: 向 POM 添加分布式管理部分。
添加部署插件。
maven-deploy-plugin
2.8.2
default-deploy
deploy
deploy
下面是您可以将分发管理部分添加到 POM 的地方:
ossrh
https://oss.sonatype.org/content/repositories/snapshots
ossrh
https://oss.sonatype.org/service/local/staging/deploy/maven2/
步骤2: 将 ossrh 服务器细节添加到 M2 _ REPO home 下的 setings.xml 中。
ossrh
your-jira-id
your-jira-pwd
注意: setings.xml 中服务器/服务器的 ID 元素应该与快照仓库的 ID 元素和 POM 文件中的仓库相同。
步骤3: 将 SCM 部分添加到 POM 中。
scm:git:git://github.com/dexecutor/dependent-tasks-executor.git
scm:git:git@github.com:dexecutor/dexecutor.git
https://github.com/dexecutor/dependent-tasks-executor
HEAD
步骤4: 添加 Maven 发布插件。
org.apache.maven.plugins
maven-release-plugin
2.5.3
true
false
forked-path
-Dgpg.passphrase=${gpg.passphrase}
org.apache.maven.scm
maven-scm-provider-gitexe
1.9.5
像在 Maven setings.xml 中添加配置文件一样添加 GPG 密码短语。
ossrh
true
[your_gpg_passphrase]
添加 Nexus 登台 Maven 插件。
org.sonatype.plugins
nexus-staging-maven-plugin
1.6.7
true
ossrh
https://oss.sonatype.org/
true
步骤5: 添加源代码和 javadoc 插件。
org.apache.maven.plugins
maven-source-plugin
3.0.1
attach-sources
jar
org.apache.maven.plugins
maven-source-plugin
2.10.4
UTF-8
attach-javadoc
步骤6: 配置为在释放时对工件进行签名。
release-sign-artifacts
performRelease
true
org.apache.maven.plugins
maven-gpg-plugin
1.6
sign-artifacts
verify
sign
步骤7: 发布 GPG 密钥对并将密钥分发到 GPG 服务器:
gpg –keyserver [KEY_SERVER] –send-key [KEY_ID]
上述情况下的 KEY _ ID 是5694AA563793429557F1727835B3BD2A223A。
其中一些关键服务器是:
第八步: 发布!
mvn clean
mvn release:prepare
mvn release:perform
第9步: 推标签和代码到您的远程回购。
git push–tags
git push origin master
步骤10: 验证 sonatype 存储库。
步骤11: 更新 Sonatype Jira 票据。
有关详细信息,请参阅此示例 POM 文件。
第一步: 撤销发布:
git reset –hard HEAD~1 (根据错误发生的时间,您可能需要再次执行此操作。)
步骤2: 删除标记。
git tag -d tagName
git push origin :refs/tags/tagName
留言与评论(共有 0 条评论) “” |