Comments (2)
我有用过一个脚本,用于发布到maven上的,你可以参考一下:
apply plugin: 'maven'
apply plugin: 'signing'
group = PROJ_GROUP
version = PROJ_VERSION
ext {
UsingSonatype = hasProperty('UsingSonatype')
isReleaseVersion = !version.endsWith("-SNAPSHOT")
// Defind in ~/.gradle/gradle.properties
ReleaseUrl = UsingSonatype ? SONATYPE_RELEASE_URL : LOCAL_RELEASE_URL
SnapshotUrl = UsingSonatype ? SONATYPE_SNAPSHOT_URL : LOCAL_SNAPSHOT_URL
Username = UsingSonatype ? SONATYPE_USER : LOCAL_USERNAME
Password = UsingSonatype ? SONATYPE_PASS : LOCAL_PASSWORD
publishAar = hasProperty('aar') ? true : false
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += configurations.compile
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
javadoc {
options{
encoding "UTF-8"
charSet 'UTF-8'
author true
version true
links "http://docs.oracle.com/javase/7/docs/api/"
links "http://androiddoc.qiniudn.com/reference/"
title PROJ_NAME
}
}
artifacts {
archives javadocJar
archives sourcesJar
}
afterEvaluate { project ->
artifacts {
archives packageReleaseJar
}
signing {
required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
pom.groupId = PROJ_GROUP
pom.artifactId = PROJ_ARTIFACT_ID
pom.version = version
repository(url: ReleaseUrl) {
authentication(userName: Username, password: Password)
}
snapshotRepository(url: SnapshotUrl) {
authentication(userName: Username, password: Password)
}
pom.project {
inceptionYear PROJ_INCEPTION_YEAR
name PROJ_NAME
packaging publishAar ? 'aar' : 'jar'
description PROJ_DESCRIPTION
url PROJ_URL
scm {
url SCM_URL
connection SCM_CONNECTION
developerConnection SCM_DEV_CONNECTION
}
licenses {
license {
name LICENSE_NAME
url LICENSE_URL
distribution LICENSE_DISTRIBUTION
}
}
developers {
developer {
id DEVELOPER_ID
name DEVELOPER_NAME
}
}
}
}
}
}
}
属性文件如下:
PROJ_GROUP=
PROJ_VERSION=
PROJ_NAME=
PROJ_DESCRIPTION=ARM SDK
PROJ_ARTIFACT_ID=
PROJ_INCEPTION_YEAR=2015
PROJ_URL=
SCM_URL=
SCM_CONNECTION=
SCM_DEV_CONNECTION=
LICENSE_NAME=The Apache Software License, Version 2.0
LICENSE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
LICENSE_DISTRIBUTION=repo
DEVELOPER_ID=
DEVELOPER_NAME=
DEVELOPER_EMAIL=
另外需要在你的~/.gradle/gradle.properties下配置如下属性:
SONATYPE_RELEASE_URL=https://oss.sonatype.org/service/local/staging/deploy/maven2
SONATYPE_SNAPSHOT_URL=https://oss.sonatype.org/content/repositories/snapshots
SONATYPE_NEXUS_USERNAME=username for sonatype
SONATYPE_NEXUS_PASSWORD=password for sonatype
LOCAL_RELEASE_URL=私服
LOCAL_SNAPSHOT_URL=私服
LOCAL_USERNAME=私服账号
LOCAL_PASSWORD=私服密码
执行的方法名应该是gradle upload
,加-PUsingSonatype
是发布到mavenCentral,如果没记错的话。
你可以自己整合下。
from gradle-publish.
非常感谢
from gradle-publish.
Related Issues (16)
- Gradle sync failed: Software caused connection abort: recv failed HOT 3
- gradle build tools 2.1.3 上传失败 HOT 21
- Error:No such property: archivesBaseName for class: org.gradle.api.internal.project.DefaultProject_Decorated HOT 13
- 引用脚本部分可以修改得更方便 HOT 9
- 不好用 HOT 2
- 请教个问题 HOT 2
- support 包和 R 文件不存在 HOT 1
- 有报错信息 HOT 6
- upload成功,无法link到jcenter HOT 2
- 关于提交aar HOT 3
- 本地环境java8怎么办 HOT 8
- 可以试试这种方式:http://www.tuicool.com/articles/UFzmuiY。 HOT 4
- 请教下多个模块之间存在依赖,怎么单独发布某个模块? HOT 5
- 无法发布 HOT 1
- SONATYPE_KEY是什么 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gradle-publish.