加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
maven_publish.gradle 4.23 KB
一键复制 编辑 原始数据 按行查看 历史
// 依赖信息
def groupIdDefined = "com.licheedev"
def artifactIdDefined = "android-serialport"
// 如果是测试版,版本号后面加上 -SNAPSHOT
def versionDefined = rootProject.ext.versionName
// 其他信息
def gitUrl = "https://github.com/licheedev/Android-SerialPort-API"
// 配置是否上传
def toUpload = true
//在根build.gradle中加入,最新版本号参考 https://github.com/Kotlin/dokka#using-dokka
//classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.4.32'
//在module的build.gradle末位加入
//apply from: '../maven_publish.gradle'
if (toUpload) {
apply plugin: 'signing'
apply plugin: 'maven-publish'
apply plugin: 'org.jetbrains.dokka'
//<editor-fold desc="打包源码和javadoc">
// 打包源码
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
failOnError false
source = android.sourceSets.main.java.sourceFiles
options {
encoding = "utf-8"
charSet 'UTF-8'
}
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
classpath += configurations.compile
}
// 打包javadoc
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
// 打包包含kotlin源码的javadoc
task kotlinDocJar(type: Jar, dependsOn: dokkaHtml) {
classifier = 'javadoc'
from dokkaHtml.outputDirectory
}
//</editor-fold>
afterEvaluate {
publishing {
publications {
mavenAndroid(MavenPublication) {
from components.release
groupId "$groupIdDefined"
artifactId "$artifactIdDefined"
version "$versionDefined"
// 上传source
artifact sourcesJar
// 上传javadoc
if (project.plugins.hasPlugin('kotlin-android')) {
artifact kotlinDocJar
} else {
artifact javadocJar
}
pom {
name = 'Android-SerialPort-API'
description = 'Android-SerialPort-API'
url = "$gitUrl"
//licenses {
// license {
// name = 'The MIT License'
// url = 'https://opensource.org/licenses/MIT'
// }
//}
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'licheedev'
name = 'John Lee'
email = 'licheedev@foxmail.com'
}
}
scm {
connection = "$gitUrl"
developerConnection = "${gitUrl}.git"
url = "$gitUrl"
}
}
}
}
repositories {
maven {
// 依赖发布地址
def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
// 配置账号密码
println "user=${ossrhUsername},key=${ossrhPassword}"
credentials {
username "${ossrhUsername}"
password "${ossrhPassword}"
}
}
}
}
signing {
sign publishing.publications.mavenAndroid
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化