代码拉取完成,页面将自动刷新
apply plugin: 'maven-publish'
apply plugin: 'signing'
Properties localProperties = new Properties()
localProperties.load(project.rootProject.file('local.properties').newDataInputStream())
localProperties.each { name, value ->
project.ext[name] = value
}
def mavenUsername = localProperties.getProperty("sonatype.username")
def mavenPassword = localProperties.getProperty("sonatype.password")
def projectGroupId = localProperties.getProperty("groupId")
def projectArtifactId = PUBLISH_ARTIFACT_ID
def projectVersionName = cfgs.versionName
def projectDescription = localProperties.getProperty("description")
def projectGitUrl = localProperties.getProperty("gitUrl")
def projectLicense = localProperties.getProperty("license")
def projectLicenseUrl = projectLicense ? "https://opensource.org/licenses/${projectLicense.toString().replace(" ", "-")} " : null
def developerAuthorEmail = localProperties.getProperty("email")
def developerAuthorId = mavenUsername
def developerAuthorName = mavenUsername
println("${mavenUsername} ${mavenPassword} - ${projectGroupId}:${projectArtifactId}:${projectVersionName}")
println("${projectLicense} - ${projectLicenseUrl}")
if (!mavenUsername || !mavenPassword || !projectGroupId || !projectArtifactId || !projectVersionName) {
println('Error:缺少参数')
return
}
if (!projectDescription || !projectGitUrl || !projectLicense || !projectLicenseUrl || !developerAuthorId || !developerAuthorName || !developerAuthorEmail) {
println('Warning:缺少可选信息')
}
def isAndroidProject = project.hasProperty('android')
if (isAndroidProject) {
println("使用Android工程方式发布")
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task javadocsJar(type: Jar, dependsOn: androidJavadocs) {
archiveClassifier.set("javadoc")
from androidJavadocs.destinationDir
}
task sourcesJar(type: Jar) {
archiveClassifier.set("sources")
from android.sourceSets.main.java.srcDirs
}
} else {
println("使用Java工程方式发布")
task javadocsJar(type: Jar, dependsOn: javadoc) {
archiveClassifier.set("javadoc")
from javadoc.destinationDir
}
task sourcesJar(type: Jar) {
archiveClassifier.set("sources")
from sourceSets.main.allJava
}
}
tasks.withType(Javadoc).all {
options {
encoding "UTF-8"
charSet 'UTF-8'
author true
version true
links "http://docs.oracle.com/javase/8/docs/api"
if (isAndroidProject) {
linksOffline "http://d.android.com/reference", "${android.sdkDirectory}/docs/reference"
}
failOnError = false
}
enabled = false
}
artifacts {
archives javadocsJar, sourcesJar
}
publishing {
publications {
aar(MavenPublication) {
groupId = projectGroupId
artifactId = projectArtifactId
version = projectVersionName
// Tell maven to prepare the generated "*.aar" file for publishing
if (isAndroidProject) {
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
} else {
artifact("$buildDir/libs/${project.getName()}.jar")
}
artifact javadocsJar
artifact sourcesJar
pom {
name = projectArtifactId
description = projectDescription
// If your project has a dedicated site, use its URL here
url = projectGitUrl
licenses {
license {
name = projectLicense
url = projectLicenseUrl
}
}
developers {
developer {
id = developerAuthorId
name = developerAuthorName
email = developerAuthorEmail
}
}
// Version control info, if you're using GitHub, follow the format as seen here
scm {
connection = "scm:git:${projectGitUrl}"
developerConnection = "scm:git:${projectGitUrl}"
url = projectGitUrl
}
withXml {
def dependenciesNode = asNode().appendNode('dependencies')
project.configurations.implementation.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
repositories {
maven {
name = projectArtifactId
def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
// You only need this if you want to publish snapshots, otherwise just set the URL
// to the release repo directly
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
// The username and password we've fetched earlier
credentials {
username mavenUsername
password mavenPassword
}
}
}
}
signing {
sign publishing.publications
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。