记录一下发布Noark到Maven中央仓库过程

0x00创建Jira工单

https://issues.sonatype.org/secure/Dashboard.jspa

第一步注册账号,创建工单,就是提个单子说明一下你要发布的信息

其中有个GroupID要注意,如果是自己买的域名,直接在描述证明一下你对这个域名的所有权,不要因为这个浪费时间

其他带有红色星号为必选项,按自己的信息写上就行了

0x01证明域名所有权

单子提交后,一会工作人员就给了一个回复

Do you own the domain noark.xyz? If not, please read:
http://central.sonatype.org/pages/choosing-your-coordinates.html

刚开始我就简单回复了一下我有,然后就没有下文了,我以为这是周末的关系所以没有回复,浪费了两天

最后参考别人证明方式,我修正了noark.xyz域名下首页添加了一个跳转向开源项目地址以表示我真的拥有这个域名

<meta http-equiv="refresh" content="0;url=https://gitee.com/xiaoe/noark3" name="" content="" />

这个方式不科学,但是简单,最好改域名解析那里哈,我是忘记账号密码了…

然后回复了老外

HI,
I own the he xyz.noark dom domain name. 
It's set up to redirect to the Gitee repo:
https://gitee.com/xiaoe/noark3
Is that sufficient proof of ownership?
Please se http://noark.xyz

嘿嘿,老外也很可爱,但最终还是给我过了…

I don't believe the redirect is working. When I navigate to noark.xyz, I'm not redirected to the gitee site. 

工单状态已变成了 RESOLVED

Configuration has been prepared, now you 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
Promote staged artifacts into repository 'Releases'
Download snapshot and release artifacts from group https://oss.sonatype.org/content/groups/public
Download snapshot, release and staged artifacts from staging group https://oss.sonatype.org/content/groups/staging
please comment on this ticket when you promoted your first release, thanks

0x02生成秘钥

下载软件 https://www.gpg4win.org/download.html

目前已是3.1.3版本了,所以生成后跟很多老的教程结果不太一样

命令行方式

gpg --gen-key

Window下是有界面,不管用什么方式这个无所谓,生成好就可以了,上传服务器(要翻墙)

gpg2 --keyserver hkp://pool.sks-keyservers.net --send-keys 4CD194B81D40708364E1608CDE1CC1DA52468EED

查看所有keys

C:\Users\mayn>gpg --list-keys
C:/Users/mayn/AppData/Roaming/gnupg/pubring.kbx
-----------------------------------------------
pub   rsa2048 2018-09-05 [SC]
      4CD194B81D40708364E1608CDE1CC1DA52468EED
uid           [ultimate] xiaoe <176543888@qq.com>
sub   rsa2048 2018-09-05 [E] [expires: 2020-09-04]

其实这里要添加一个参数,才能看到短ID

C:\Users\mayn>gpg --list-keys --keyid-format short
C:/Users/mayn/AppData/Roaming/gnupg/pubring.kbx
-----------------------------------------------
pub   rsa2048/52468EED 2018-09-05 [SC]
      4CD194B81D40708364E1608CDE1CC1DA52468EED
uid         [ultimate] xiaoe <176543888@qq.com>
sub   rsa2048/15567893 2018-09-05 [E] [expires: 2020-09-04]

是不是配置Gradle提示GPG无效呢,新版本要用下面这个命令导出GPG格式

C:\Users\mayn>gpg --export-secret-keys -o secring.gpg

0x03配置脚本

配置Gradle脚本,这个脚本已修正好了,直接参考复制…

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'signing'
	
group = 'xyz.noark'  
version = '3.1.18.Final'
sourceCompatibility = 1.8  
targetCompatibility = 1.8  

[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

repositories {
    maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
    mavenCentral()
    jcenter()
}

dependencies {
	testImplementation 'junit:junit:4.12'
}

jar {
    manifest.attributes provider: '小流氓'
	manifest.attributes["Created-By"] = "${System.getProperty("java.version")} (${System.getProperty("java.specification.vendor")})"
	manifest.attributes["Implementation-Title"] = project.name
	manifest.attributes["Implementation-Version"] = project.version
}
    
javadoc {
    options{
    	encoding "UTF-8"
		charSet 'UTF-8'
    	author true
    	version true
    	links "http://docs.oracle.com/javase/8/docs/api/"
    }
}
    
ext."signing.keyId"='15567893'
ext."signing.password"=System.getenv('SIGNING_PASSWORD')
ext."signing.secretKeyRingFile"=System.getenv('SIGNING_SECRETKEYRINGFILE')
	
signing {
	sign configurations.archives
}
	
uploadArchives {
	repositories {
	    mavenDeployer {
	        beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
	
	        repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
	            authentication(userName: System.getenv('OSSRH_USER'), password: System.getenv('OSSRH_PASSWORD'))
	        }
	
	        snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
	            authentication(userName: System.getenv('OSSRH_USER'), password: System.getenv('OSSRH_PASSWORD'))
	        }
	            
	        pom.project {
	        	name 'Noark'
	        	packaging 'jar'
	        	description 'This is a game server framework.'
	        	url 'https://noark.xyz'
	
	        	scm {
	          		connection 'scm:git:git@gitee.com:xiaoe/noark3.git'
	          		developerConnection 'scm:git:git@gitee.com:xiaoe/noark3.git'
	          		url 'https://gitee.com/xiaoe/noark3/'
	        	}
	
	        	licenses {
	          		license {
	            		name 'The Apache License, Version 2.0'
	            		url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
	          		}
	        	}
	
	        	developers {
	          		developer {
	            		id 'xiaoe'
		            	name '小流氓'
		            	email '176543888@qq.com'
		            	url "http://blog.noark.xyz"
	          		}
	        	}
	        }
	    }
	}
}
	
task sourceJar(type: Jar) {
	from sourceSets.main.allJava
	classifier = 'sources'
}
	
task javadocJar(type: Jar) {
	from javadoc
	classifier = 'javadoc'
}
	
artifacts {
    archives sourceJar
    archives javadocJar
}

发布,如果提示什么异常信息,可以在单子上留言问一下工作人员,当时我之前发布一个版本,POM与签名都有问题我就删了central_bundles-14313,只能求助

I uploaded a version before and when logining https://oss.sonatype.org/#stagingRepositories,I found some problems with POM. So I droped the central_bundles-14313.

Now an exception occurs when I upload again, it shows as below.

'Failed to deploy artifacts: Could not transfer artifact xyz.noark:noa:noark-asm:jar:3.1.19.Final from/to remote (e (https://oss.sonatype.org/service/local/staging/deploy /maven2/): Access denied to: https://oss.sonatype.org/service/local/staging/deploy/maven2/xyz/noark/noark-asm/3.1.19.Final/noark-asm-3.1.19 .Final.jar, ReasonPhrase: Forbidden.'

If the version is end by -SNAPSHOT, it can be published successfully.

Here you may check all the published content through below, yet it always shows failure when publishing of 3.1.19.Final.

'https://oss.sonatype.org/content/groups/public/xyz/noark/noark-asm/3.1.19-SNAPSHOT/'

Now what should i do? Please help.Thanks and apprecaite.

第二天工作人员还是给与了回复与处理

There was a backend issue with your credentials that I've resolved. Please retry your deployment. 

再次发布,正常上传了。

0x04发布

登录https://oss.sonatype.org/#stagingRepositories
账号密码就是前台注册的Jira单子账号密码

搜索noark就可以看到自己的那个仓库了,xyznoark-1000,这个仓库里就是刚刚发布到sonatype仓库的项目,点击左上角的close按钮,会进行相关检测,之前POM与签名有问题就是这里提示的

以为简单的删除就可以重来,结果不是我想得这样,所以有了上面的求助故事,这次发布全部分通过。

项目状态变为closed之后,便可以点击release按钮,输入必要的description信息后,就发布成功了。

此时单子下面会自动回复了一条

Central sync is activated for xyz.noark. After you successfully release, your component will be published to Central, typically within 10 minutes, though updates to search.maven.org can take up to two hours.

好像这就发布成功了,编写代码测试,可以拉到版本了….

最终我不是去单子上感谢了一下工作人员…

结论,学好英语还是很有必要的,好怀念大学的英语老师,长得跟个校花似的….

转载请注明原地址: http://blog.noark.xyz/article/2018/9/1/发布maven中央仓库小记/