上传jar包到maven中央仓库,本地maven相关配置
软件编程
196
皇太极
: 2021-04-17 19:20:13

本文只介绍maven相关的配置,具体如何注册账号相关的需要自己查阅资料。

  1. # 列举证书,可以看到证书路径
  2. gpg --list-keys
  3. /Users/apple/.gnupg/pubring.kbx
  4. # 到目录下修改default 证书
  5. cd /Users/apple/.gnupg
  6. cat gpg.conf
  7. # 内容如下
  8. use-agent
  9. pinentry-mode loopback
  10. no-emit-version
  11. default-key 1234C23F5446B3DD7777681F1F56BFB106A71234
  • 配置setting.xml
  1. <servers>
  2. <server>
  3. <id>ossrh</id>
  4. <username>在sonatype上注册的username</username>
  5. <password>在sonatype上注册的password</password>
  6. </server>
  7. </servers>
  8. <!-- 分割线 -->
  9. <profile>
  10. <id>ossrh</id>
  11. <activation>
  12. <activeByDefault>true</activeByDefault>
  13. </activation>
  14. <properties>
  15. <gpg.executable>gpg2</gpg.executable>
  16. <gpg.passphrase>证书的密码</gpg.passphrase>
  17. </properties>
  18. </profile>
  • 配置pom.xml
  1. <distributionManagement>
  2. <snapshotRepository>
  3. <!-- 这里的id要与maven setting.xml中server的id一致 -->
  4. <id>ossrh</id>
  5. <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
  6. </snapshotRepository>
  7. <repository>
  8. <id>ossrh</id>
  9. <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
  10. </repository>
  11. </distributionManagement>
  12. <!-- Gpg plugin for signature authentication -->
  13. <plugin>
  14. <groupId>org.apache.maven.plugins</groupId>
  15. <artifactId>maven-gpg-plugin</artifactId>
  16. <version>1.6</version>
  17. <executions>
  18. <execution>
  19. <id>sign-artifacts</id>
  20. <phase>verify</phase>
  21. <goals>
  22. <goal>sign</goal>
  23. </goals>
  24. </execution>
  25. </executions>
  26. </plugin>
  • 发布命令
    mvn clean deploy -P oss -Dgpg.passphrase="你的证书密码" -Dmaven.test.skip=true -e
    或直接使用
    mvn clean install deploy