当前位置:   article > 正文

自建Maven项目如何发布到Sonatype和Central中央仓库中(三)_maven central repository sonatype

maven central repository sonatype

自建Maven项目如何发布到Sonatype和Central中西仓库中(一)

1.配置Maven库的全局Setting.xml文件

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

2.配置Maven项目根POM文件,增加发布到中央仓库的profile

  1. <profiles>
  2. <profile>
  3. <id>sonatype-release</id>
  4. <activation>
  5. <activeByDefault>true</activeByDefault>
  6. </activation>
  7. <build>
  8. <plugins>
  9. <plugin>
  10. <groupId>org.apache.maven.plugins</groupId>
  11. <artifactId>maven-source-plugin</artifactId>
  12. <version>2.2.1</version>
  13. <executions>
  14. <execution>
  15. <phase>package</phase>
  16. <goals>
  17. <goal>jar-no-fork</goal>
  18. </goals>
  19. </execution>
  20. </executions>
  21. </plugin>
  22. <plugin>
  23. <groupId>org.apache.maven.plugins</groupId>
  24. <artifactId>maven-javadoc-plugin</artifactId>
  25. <version>2.9.1</version>
  26. <configuration>
  27. <show>private</show>
  28. <nohelp>true</nohelp>
  29. <charset>UTF-8</charset>
  30. <encoding>UTF-8</encoding>
  31. <docencoding>UTF-8</docencoding>
  32. <additionalparam>-Xdoclint:none</additionalparam>
  33. </configuration>
  34. <executions>
  35. <execution>
  36. <phase>package</phase>
  37. <goals>
  38. <goal>jar</goal>
  39. </goals>
  40. </execution>
  41. </executions>
  42. </plugin>
  43. <plugin>
  44. <groupId>org.apache.maven.plugins</groupId>
  45. <artifactId>maven-gpg-plugin</artifactId>
  46. <version>1.6</version>
  47. <executions>
  48. <execution>
  49. <phase>verify</phase>
  50. <goals>
  51. <goal>sign</goal>
  52. </goals>
  53. </execution>
  54. </executions>
  55. </plugin>
  56. <plugin>
  57. <groupId>org.apache.maven.plugins</groupId>
  58. <artifactId>maven-compiler-plugin</artifactId>
  59. <version>3.7.0</version>
  60. <configuration>
  61. <source>1.8</source>
  62. <target>1.8</target>
  63. </configuration>
  64. </plugin>
  65. <!--Release -->
  66. <plugin>
  67. <groupId>org.apache.maven.plugins</groupId>
  68. <artifactId>maven-release-plugin</artifactId>
  69. <version>2.5.1</version>
  70. </plugin>
  71. <plugin>
  72. <artifactId>maven-deploy-plugin</artifactId>
  73. <version>2.8.2</version>
  74. <executions>
  75. <execution>
  76. <id>default-deploy</id>
  77. <phase>deploy</phase>
  78. <goals>
  79. <goal>deploy</goal>
  80. </goals>
  81. </execution>
  82. </executions>
  83. </plugin>
  84. <plugin>
  85. <groupId>org.sonatype.plugins</groupId>
  86. <artifactId>nexus-staging-maven-plugin</artifactId>
  87. <version>1.6.7</version>
  88. <extensions>true</extensions>
  89. <configuration>
  90. <serverId>sonatype</serverId>
  91. <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
  92. <autoReleaseAfterClose>true</autoReleaseAfterClose>
  93. </configuration>
  94. </plugin>
  95. <plugin>
  96. <groupId>org.apache.maven.plugins</groupId>
  97. <artifactId>maven-scm-plugin</artifactId>
  98. <version>1.8.1</version>
  99. </plugin>
  100. </plugins>
  101. </build>
  102. <!-- 这里配置的ossrh要与settings.xml的一致,不然发布会出错 -->
  103. <distributionManagement>
  104. <snapshotRepository>
  105. <id>sonatype</id>
  106. <name>Sonatype Nexus Snapshots</name>
  107. <url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
  108. </snapshotRepository>
  109. <repository>
  110. <id>sonatype</id>
  111. <name>Nexus Release Repository</name>
  112. <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
  113. </repository>
  114. </distributionManagement>
  115. </profile>
  116. </profiles>

3.发布项目到中央仓库

 mvn clean deploy -Psonatype-release

4.需要注意的点

a.根POM文件,必须配置 name、url、description

b.必须生成source和javadoc。在maven plugin中配置响应的插件,见上文

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/87454
推荐阅读
相关标签
  

闽ICP备14008679号