经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 软件/图像 » Maven » 查看文章
发布自己的项目到Maven中央仓库中
来源:cnblogs  作者:柒木木木  时间:2023/5/30 10:02:39  对本文有异议

注册账号和生成GPG生成密钥教程

主要看注册账号和生成GPG密匙部分就行了,出现问题可以先在这两个地方找

gpg加密发布jar包到maven中央仓库详细过程以及踩的坑_佛系猿秦大昊的博客-CSDN博客

来开源吧!发布开源组件到 MavenCentral 仓库超详细攻略 - 掘金 (juejin.cn)

1. 修改Maven配置文件

全局配置文件添加

  1. <server>
  2. <id>sonatype-qimu</id>
  3. <username>sonatype账号</username>
  4. <password>密码</password>
  5. </server>

2. 修改项目pom,xml

在Maven项目的pom.xml中添加licenses、developers、scm、profiles、plugins、distributionManagement等内容,示例:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.7.0</version>
  9. <relativePath/> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>icu.qimuu</groupId>
  12. <artifactId>EazyWeb</artifactId>
  13. <version>0.0.1</version>
  14. <name>EazyWeb</name>
  15. <description>EazyWeb</description>
  16. <properties>
  17. <maven.compiler.source>1.8</maven.compiler.source>
  18. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  19. </properties>
  20. <licenses>
  21. <license>
  22. <name>The Apache Software License, Version 2.0</name>
  23. <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
  24. </license>
  25. </licenses>
  26. <!-- 根据自己实际情况填写 -->
  27. <developers>
  28. <developer>
  29. <name>qimu</name>
  30. <email>2483482026@qq.com</email>
  31. </developer>
  32. </developers>
  33. <!-- 与申请issue时填写的SCM保持一致 -->
  34. <scm>
  35. <connection>https://github.com/qimu666/EazyWeb.git</connection>
  36. <developerConnection>https://github.com/qimu666/EazyWeb.git</developerConnection>
  37. <url>https://github.com/qimu666/EazyWeb</url>
  38. </scm>
  39. <profiles>
  40. <profile>
  41. <!-- 这个id就是打包时的 -P 参数 -->
  42. <id>release</id>
  43. <build>
  44. <plugins>
  45. <!-- Source插件-->
  46. <plugin>
  47. <groupId>org.apache.maven.plugins</groupId>
  48. <artifactId>maven-source-plugin</artifactId>
  49. <version>2.2.1</version>
  50. <executions>
  51. <execution>
  52. <phase>package</phase>
  53. <goals>
  54. <goal>jar-no-fork</goal>
  55. </goals>
  56. </execution>
  57. </executions>
  58. </plugin>
  59. <!-- Javadoc插件 -->
  60. <plugin>
  61. <groupId>org.apache.maven.plugins</groupId>
  62. <artifactId>maven-javadoc-plugin</artifactId>
  63. <version>2.9.1</version>
  64. <executions>
  65. <execution>
  66. <phase>package</phase>
  67. <goals>
  68. <goal>jar</goal>
  69. </goals>
  70. <!-- -Xdoclint:none 是为了避免生成apidoc的时候检查过于严格而报错-->
  71. <configuration>
  72. <additionalparam>-Xdoclint:none</additionalparam>
  73. </configuration>
  74. </execution>
  75. </executions>
  76. </plugin>
  77. <!-- GPG加密插件 -->
  78. <plugin>
  79. <groupId>org.apache.maven.plugins</groupId>
  80. <artifactId>maven-gpg-plugin</artifactId>
  81. <version>1.6</version>
  82. <executions>
  83. <execution>
  84. <phase>verify</phase>
  85. <goals>
  86. <goal>sign</goal>
  87. </goals>
  88. </execution>
  89. </executions>
  90. </plugin>
  91. </plugins>
  92. </build>
  93. <!-- snapshotRepository与repository的id应与setting.xml中添加的server的id一致 -->
  94. <distributionManagement>
  95. <snapshotRepository>
  96. <id>sonatype-qimu</id>
  97. <url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
  98. </snapshotRepository>
  99. <repository>
  100. <id>sonatype-qimu</id>
  101. <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
  102. </repository>
  103. </distributionManagement>
  104. </profile>
  105. </profiles>
  106. <dependencies>
  107. <dependency>
  108. <groupId>org.springframework.boot</groupId>
  109. <artifactId>spring-boot-starter-web</artifactId>
  110. </dependency>
  111. <dependency>
  112. <groupId>org.springframework.boot</groupId>
  113. <artifactId>spring-boot-configuration-processor</artifactId>
  114. <optional>true</optional>
  115. </dependency>
  116. <dependency>
  117. <groupId>com.github.xiaoymin</groupId>
  118. <artifactId>knife4j-spring-boot-starter</artifactId>
  119. <version>3.0.3</version>
  120. </dependency>
  121. <dependency>
  122. <groupId>org.projectlombok</groupId>
  123. <artifactId>lombok</artifactId>
  124. <optional>true</optional>
  125. </dependency>
  126. <dependency>
  127. <groupId>org.springframework.boot</groupId>
  128. <artifactId>spring-boot-starter-test</artifactId>
  129. <scope>test</scope>
  130. </dependency>
  131. </dependencies>
  132. </project>

3. 控制台执行命令

  1. mvn clean deploy -P release

原文链接:https://www.cnblogs.com/qimu666/p/17442423.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号