bingoogolapple.github.io
bingoogolapple.github.io copied to clipboard
通过gradle发布aar到maven中央仓库
2.创建一个issue
Project:Community Support - Open Source Project Repository Hosting
Issue Type:New Project
Summary:项目名即可
(等到Status变成RESOLVED时才能执行第8步)
3.GnuPG签名 下载
安装:gpg --gen-key (除了姓名、邮箱、备注外其他都可以使用默认配置,密码在接下来的第4步中会用到)
查看key内容:gpg --list-keys
/home/bingoogol/.gnupg/pubring.gpg
----------------------------------
pub 2048R/7CB0B0XX 2014-10-17
(这里的keyid就是7CB0B0XX,在第4步中会用到)
上传到服务器:gpg --keyserver hkp://pool.sks-keyservers.net --send-keys keyid
4.在/home/bingoogol/.gradle目录下创建gradle.properties文件
NEXUS_USERNAME=第1步中注册的用户名
NEXUS_PASSWORD=第1步中注册的密码
signing.keyId=第3步中创建的keyid
signing.password=第3步中输入的密码
signing.secretKeyRingFile=/home/计算机用户名/.gnupg/secring.gpg
windows用户 C:\Users\用户名\AppData\Roaming\gnupg
5.gradle.properties
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Settings specified in this file will override any Gradle settings
# configured through the IDE.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
VERSION_NAME=1.0.0
VERSION_CODE=1
GROUP=cn.bingoogolapple.loon
POM_NAME=Android Annotation Library
POM_ARTIFACT_ID=library
POM_PACKAGING=aar
POM_DESCRIPTION=Android Annotation Library
POM_URL=https://github.com/bingoogolapple/Loon
POM_SCM_URL=https://github.com/bingoogolapple/Loon
POM_SCM_CONNECTION=scm:https://github.com/bingoogolapple/Loon.git
POM_SCM_DEV_CONNECTION=scm:https://github.com/bingoogolapple/Loon.git
POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=bingoogolapple
POM_DEVELOPER_NAME=bingoogolapple
6.gradle-mvn-push.gradle
/*
* Copyright 2013 Chris Banes
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
apply plugin: 'maven'
apply plugin: 'signing'
def isReleaseBuild() {
return VERSION_NAME.contains("SNAPSHOT") == false
}
def getReleaseRepositoryUrl() {
return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
}
def getSnapshotRepositoryUrl() {
return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
: "https://oss.sonatype.org/content/repositories/snapshots/"
}
def getRepositoryUsername() {
return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
}
def getRepositoryPassword() {
return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
}
afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME
repository(url: getReleaseRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
snapshotRepository(url: getSnapshotRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL
scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}
licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}
developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}
}
signing {
required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
task apklib(type: Zip){
appendix = extension = 'apklib'
from 'AndroidManifest.xml'
into('res') {
from 'res'
}
into('src') {
from 'src'
}
}
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath() .join(File.pathSeparator))
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
archives apklib
}
}
7.build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
applicationId "cn.bingoogolapple.loon.library"
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}
}
apply from: './gradle-mvn-push.gradle'
8.发布snapshot和release版本
gradle -q uploadArchives
9.在Sonatype OSS中执行Close and Release操作
登陆后点击左边Build Promotion中的Staging Repositories
搜索入第2步group查询
选中后先点击close,再点击release