02. 构建脚本
Gradle 构建
和
$ cat userguide/artifacts/uploading/build.gradle
## jar类型的artifact
task myJar(type: Jar)
artifacts {
archives myJar
}
## file类型的artifact
def someFile = file('build/somefile.txt')
artifacts {
archives someFile
}
## 根据自定义task来完成artifact
task myTask(type: MyTaskType) {
destFile = file('build/somefile.txt')
}
artifacts {
archives(myTask.destFile) {
name 'my-artifact'
type 'text'
builtBy myTask
}
}
## 根据自定义task来完成artifact
task generate(type: MyTaskType) {
destFile = file('build/somefile.txt')
}
artifacts {
archives file: generate.destFile, name: 'my-artifact', type: 'text', builtBy: generate
}
这样就简单地定义了好几种Java plugin
都默认定义了
项目发布
Maven 中心库
首先我们需要准备账户,并且创建项目。首先,在

创建完毕后就等待一段时间,刷新页面。当状态变为“resolved”,然后你就可以使用
项目配置
apply plugin: 'maven'
apply plugin: 'signing'
signing {
sign configurations.archives
}
group = "io.github.meetsl"
archivesBaseName = "SCardView"
version = "1.0"
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment {
MavenDeployment deployment -> signing.signPom(deployment)
}
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name 'SCardView'
packaging 'aar'
description 'This is a view that is similar to the CardView of google,but it can change the position of shadow and the shadow color of it . '
url 'https://github.com/meetsl/SCardView-master'
scm {
connection 'scm:git:https://github.com/meetsl/SCardView-master.git'
developerConnection 'scm:git:https://github.com/meetsl/SCardView-master.git'
url 'https://github.com/meetsl/SCardView-master.git'
}
licenses {
license {
name 'The Apache License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id 'xxxxxx'
name 'xxxxxx'
email 'xxxxxxxx.com'
}
}
}
}
}
}
在上面的代码中,大家请将根域中的
密钥
首先我们需要创建一个
上传完成之后,就可以正式配置签名信息以及你的
signing.keyId= 密钥的ID(注意一下,密钥ID 是一个八个字节的字符串 Kleopatra工具需要悬浮在 密钥ID 一栏查看)
signing.password= 密钥的密码 (生成证书时填写的密码)
signing.secretKeyRingFile=..\\secret.gpg(secret.gpg为私密证书。将导出的私密证书,放置在工程目录下)
ossrhUsername= sonatype 账号
ossrhPassword= sonatype 密码
配置成功之后,按照下图运行
正式发布
通过上面的步骤,我们只是把开源库放置在了一个私有的
-
进入以下地址
:https://oss.sonatype.org/ ,并使用sonatype 的账号密码在右上角进行登录。 -
登录成功,在左侧的导航栏,你会看到一个叫做
Staging Repositories 的选项,点击它,你会发现出现了很多列表选项。

根据列表名称,你会发现一个以你的
私有仓库
apply plugin: 'maven'
uploadArchives {
repositories {
ivy {
credentials {
username "username"
password "pw"
}
url "http://repo.mycompany.com"
}
}
}