自己构思一个好的项目到github,然后发布到maven,供别人通过maven进行依赖使用。然后写点文档什么的,就可以到github骗小星星了。
Project: Community Support - Open Source Project Repository Hosting (OSSRH)
Issue TypeRequired: New Project
Summary: 概述
Group Id:io.github.thirdparty-core
Project URL:项目站点,如:https://github.com/thirdparty-core/kernel
SCM url:项目源码仓库,如:https://github.com/thirdparty-core/kernel.git
io.github.thirdparty-core has been prepared, now user(s) bugboy can:
Deploy snapshot artifacts into repository https://oss.sonatype.org/content/repositories/snapshots
Deploy release artifacts into the staging repository https://oss.sonatype.org/service/local/staging/deploy/maven2
Release staged artifacts into repository 'Releases'
please comment on this ticket when you promoted your first release, thanks
到这,说明你可以进行release你的项目了。
准备pgp的公私钥。
gpg --version
校验是否安装成功。gpg --gen-key
生成密钥对,生成时会让你提示输入用户名密码邮箱,输入的密码需要记住,后续Release时会用到,建议使用注册https://issues.sonatype.org/网站用户时的密码,并用小本子记录好。gpg --list-keys
查看公钥。gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys <公钥key>
将公钥信息发送到ubuntu.com服务器,后续推送maven仓库会做校验。gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys <公钥key>
查询公钥是否推送成功。准备要发布的项目。下面以我自己的项目为例。
parent pom配置如下:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0modelVersion>
<groupId>io.github.thirdparty-coregroupId>
<artifactId>kernelartifactId>
<packaging>pompackaging>
<version>1.0.1-preversion>
<name>kernelname>
<description>Some core third-party implementationsdescription>
<url>https://github.com/thirdparty-core/kernelurl>
<modules>
<module>spark-hbasemodule>
modules>
<distributionManagement>
<snapshotRepository>
<id>sonatype-nexus-snapshotsid>
<name>Sonatype Nexus Snapshotsname>
<url>https://oss.sonatype.org/content/repositories/snapshotsurl>
snapshotRepository>
<repository>
<id>sonatype-nexus-stagingid>
<name>Nexus Release Repositoryname>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2url>
repository>
distributionManagement>
<licenses>
<license>
<name>The Apache Software License, Version 2.0name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txturl>
<distribution>repodistribution>
license>
licenses>
<scm>
<url>https://github.com/thirdparty-core/kernel.giturl>
<connection>scm:git:git://github.com/thirdparty-core/kernel.gitconnection>
<developerConnection>scm:git:ssh://github.com/thirdparty-coredeveloperConnection>
scm>
<developers>
<developer>
<name>bugboyname>
<email>[email protected]email>
<url>https://github.com/thirdparty-coreurl>
developer>
developers>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-gpg-pluginartifactId>
<version>1.6version>
<executions>
<execution>
<id>sign-artifactsid>
<phase>verifyphase>
<goals>
<goal>signgoal>
goals>
execution>
executions>
plugin>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-release-pluginartifactId>
<version>2.5.3version>
<configuration>
<autoVersionSubmodules>trueautoVersionSubmodules>
<useReleaseProfile>falseuseReleaseProfile>
<releaseProfiles>releasereleaseProfiles>
<goals>deploygoals>
configuration>
plugin>
plugins>
build>
project>
spark-hbase的pom如下:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>kernelartifactId>
<groupId>io.github.thirdparty-coregroupId>
<version>1.0.1-preversion>
parent>
<modelVersion>4.0.0modelVersion>
<artifactId>spark-hbaseartifactId>
<version>1.0.1-preversion>
<packaging>jarpackaging>
<name>spark-hbasename>
<properties>
<spark.version>2.4.4spark.version>
<hadoop.version>2.8.5hadoop.version>
<hbase.version>2.2.2hbase.version>
<scala.version>2.11.12scala.version>
<scala.lib.version>2.11scala.lib.version>
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
<scope>providedscope>
properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfishgroupId>
<artifactId>javax.elartifactId>
<version>3.0.1-b08version>
dependency>
dependencies>
dependencyManagement>
<dependencies>
<dependency>
<groupId>org.scala-langgroupId>
<artifactId>scala-libraryartifactId>
<version>${scala.version}version>
<scope>providedscope>
dependency>
<dependency>
<groupId>org.apache.sparkgroupId>
<artifactId>spark-core_${scala.lib.version}artifactId>
<version>${spark.version}version>
<scope>${scope}scope>
<exclusions>
<exclusion>
<artifactId>org.scala-langartifactId>
<groupId>scala-librarygroupId>
exclusion>
exclusions>
dependency>
<dependency>
<groupId>org.apache.sparkgroupId>
<artifactId>spark-sql_${scala.lib.version}artifactId>
<version>${spark.version}version>
<scope>${scope}scope>
<exclusions>
<exclusion>
<artifactId>org.scala-langartifactId>
<groupId>scala-librarygroupId>
exclusion>
exclusions>
dependency>
<dependency>
<groupId>org.apache.hadoopgroupId>
<artifactId>hadoop-clientartifactId>
<version>${hadoop.version}version>
<scope>${scope}scope>
dependency>
<dependency>
<groupId>org.apache.hbasegroupId>
<artifactId>hbase-clientartifactId>
<version>${hbase.version}version>
<scope>${scope}scope>
dependency>
<dependency>
<groupId>org.apache.hbasegroupId>
<artifactId>hbase-serverartifactId>
<version>${hbase.version}version>
<scope>${scope}scope>
dependency>
<dependency>
<groupId>org.apache.hbasegroupId>
<artifactId>hbase-mapreduceartifactId>
<version>${hbase.version}version>
<scope>${scope}scope>
dependency>
<dependency>
<groupId>org.apache.hbasegroupId>
<artifactId>hbase-commonartifactId>
<version>${hbase.version}version>
<scope>${scope}scope>
dependency>
<dependency>
<groupId>org.apache.hbasegroupId>
<artifactId>hbase-testing-utilartifactId>
<version>${hbase.version}version>
<scope>testscope>
dependency>
dependencies>
<build>
<plugins>
<plugin>
<groupId>net.alchim31.mavengroupId>
<artifactId>scala-maven-pluginartifactId>
<version>3.2.0version>
<configuration>
<charset>${project.build.sourceEncoding}charset>
<scalaVersion>${scala.version}scalaVersion>
<args>
<arg>-featurearg>
<arg>-target:jvm-1.8arg>
args>
<source>1.8source>
<target>1.8target>
configuration>
<executions>
<execution>
<id>scala-compile-firstid>
<phase>process-resourcesphase>
<goals>
<goal>add-sourcegoal>
<goal>compilegoal>
goals>
execution>
<execution>
<id>scala-test-compileid>
<phase>process-test-resourcesphase>
<goals>
<goal>testCompilegoal>
goals>
execution>
executions>
plugin>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-javadoc-pluginartifactId>
<version>2.9.1version>
<executions>
<execution>
<phase>packagephase>
<goals>
<goal>jargoal>
goals>
execution>
executions>
plugin>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-source-pluginartifactId>
<version>3.0.1version>
<executions>
<execution>
<id>attach-sourcesid>
<goals>
<goal>jar-no-forkgoal>
goals>
execution>
executions>
plugin>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-compiler-pluginartifactId>
<version>3.6.0version>
<configuration>
<encoding>utf-8encoding>
<source>1.8source>
<target>1.8target>
configuration>
plugin>
plugins>
build>
project>
注意,进行发布的时候,必须要有发布包,源码包,文档包。
修改maven的setting.xml文件,看到我maven在我自己目录下的.m2/setting.xml,该文件我没有找到,我是下载的maven安装包中,将安装包中的conf下的setting.xml拷贝过来放这的。编辑该文件,在services节点下添加:
<servers>
<server>
<id>sonatype-nexus-snapshotsid>
<username>bugboyusername>
<password>上文中网站注册时的密码password>
server>
<server>
<id>sonatype-nexus-stagingid>
<username>bugboyusername>
<password>上文中网站注册时的密码password>
server>
servers>
因为要用到好多密码,所以为了方便不混淆,整个过程都用注册时的密码,所以用小本子记录下来。
编译项目,打包。
mvn install
mvn scala:doc
,之后会看到在spark-hbase的target目录下生成一个site目录,里面有一个scaladocs文件夹。此时,在target目录下新建一个名为apidocs的目录,并将site目录中的scaladocs拷贝到apidocs目录下,注意目录名不更更改。mvn install
,结束后会在spark-hbase的target目录下看到*-javadoc.jar,*-sources.jar,*.jar
等文件,此时要发布的文件都已经准备好了。发布。运行mvn deploy
,会看到发布过程中会进行相关文件的上传。外网,有点慢。
上传结束后,访问https://oss.sonatype.org/#stagingRepositories查看发布好的构件,点击左侧的Staging Repositories,会看到你发布的构建,其根据group-id-1001来命名的,并且每成功上传一次,后面的编号自增一次。选择最大的编号即为最新发布的。选择要发布的构建,此时状态为Open
选中构件,并点击上方的 Close–>Confirm 在下边的Activity选项卡中查看状态。注意,Close时会分步骤检查你发布的构建是否都包含它要求需要的东西,其中root pom必须要有
kernel
Some core third-party implementations
https://github.com/thirdparty-core/kernel
当状态变成closed后,执行 Release–>Confirm 并在下边的Activity选项卡中查看状态。成功后构件自动删除,一小段时间(约1-2个小时)后即可同步到maven的中央仓库。届时会有邮件通知。
之后到Issue增加Comment,留言致谢并表示发布已经完成,请工作人员关闭Issue。
搜索自己发布的包:
https://search.maven.org/
或者新建一个maven项目,依赖测试以下。
参考文章:https://blog.csdn.net/sinat_23290725/article/details/85018092
致谢!