Improve Android compatibility and Maven publication configuration
This commit is contained in:
1 parent
96c1d26a57
commit
e9d9281333
16 files changed
+226
-143
No files matched your search
@@ -1,3 +1,7 @@
|
||||
import org.gradle.api.credentials.HttpHeaderCredentials
|
||||
import org.gradle.api.publish.tasks.GenerateModuleMetadata
|
||||
import org.gradle.authentication.http.HttpHeaderAuthentication
|
||||
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'signing'
|
||||
|
||||
@@ -6,6 +10,33 @@ ext {
|
||||
PUBLISH_VERSION = rootProject.ext.mavenVersion
|
||||
}
|
||||
|
||||
group = PUBLISH_GROUP_ID
|
||||
version = PUBLISH_VERSION
|
||||
|
||||
// 项目依赖在 POM 中的坐标需与已发布构件的 artifactId 对应
|
||||
def publishedArtifactIds = [
|
||||
'Aria' : 'core',
|
||||
'AriaAnnotations': 'annotations',
|
||||
'AriaCompiler' : 'compiler',
|
||||
'PublicComponent': 'public',
|
||||
'HttpComponent' : 'http',
|
||||
'M3U8Component' : 'm3u8',
|
||||
'SFtpComponent' : 'sftp',
|
||||
'FtpComponent' : 'ftp'
|
||||
]
|
||||
|
||||
def giteaToken = project.findProperty('giteaToken') ?: System.getenv('GITEA_TOKEN')
|
||||
|
||||
// Gitea 不支持覆盖版本,也不校验签名;本地或显式指定仓库地址时仍走原流程
|
||||
def giteaPublish = !isLocal() &&
|
||||
!project.hasProperty('RELEASE_REPOSITORY_URL') &&
|
||||
!project.hasProperty('SNAPSHOT_REPOSITORY_URL')
|
||||
|
||||
// 部分模块名与发布 artifactId 不一致,禁用 .module 元数据避免消费方按项目名解析
|
||||
tasks.withType(GenerateModuleMetadata).configureEach {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
|
||||
//编译groovy代码时采用 UTF-8
|
||||
tasks.withType(GroovyCompile) {
|
||||
@@ -55,13 +86,13 @@ static def localMavenRepo() {
|
||||
def getReleaseRepositoryUrl() {
|
||||
return isLocal() ? localMavenRepo()
|
||||
: hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
|
||||
: 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/'
|
||||
: 'https://gitea.ttstd.com/api/packages/maven/maven'
|
||||
}
|
||||
|
||||
def getSnapshotRepositoryUrl() {
|
||||
return isLocal() ? localMavenRepo()
|
||||
: hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
|
||||
: 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
|
||||
: 'https://gitea.ttstd.com/api/packages/maven/maven'
|
||||
}
|
||||
|
||||
def isLocal() {
|
||||
@@ -71,6 +102,8 @@ def isLocal() {
|
||||
afterEvaluate { project ->
|
||||
if (isLocal()) {
|
||||
println("上传到本地仓库")
|
||||
} else if (giteaPublish) {
|
||||
println("上传到 Gitea 私有仓库")
|
||||
} else {
|
||||
println("上传到中央仓库")
|
||||
}
|
||||
@@ -162,7 +195,10 @@ afterEvaluate { project ->
|
||||
archiveBaseName = "${JAR_PREFIX}${project.name}-cache"
|
||||
}
|
||||
|
||||
artifact androidLibraryJar
|
||||
artifact(androidLibraryJar) {
|
||||
// 作为附属构件,避免与主 AAR 争抢无 classifier 主构件导致 packaging 变 pom
|
||||
classifier = 'classes'
|
||||
}
|
||||
artifact androidSourcesJar
|
||||
artifact androidJavadocsJar
|
||||
|
||||
@@ -211,26 +247,57 @@ afterEvaluate { project ->
|
||||
//分支地址:
|
||||
url = rootProject.ext.mavenCentralTreeURL
|
||||
}
|
||||
withXml {
|
||||
asNode().dependencies?.dependency?.each { dep ->
|
||||
def projectName = dep.artifactId?.text()
|
||||
if (projectName && publishedArtifactIds.containsKey(projectName)) {
|
||||
if (dep.groupId) {
|
||||
dep.groupId[0].value = PUBLISH_GROUP_ID
|
||||
} else {
|
||||
dep.appendNode('groupId', PUBLISH_GROUP_ID)
|
||||
}
|
||||
dep.artifactId[0].value = publishedArtifactIds[projectName]
|
||||
if (dep.version) {
|
||||
dep.version[0].value = PUBLISH_VERSION
|
||||
} else {
|
||||
dep.appendNode('version', PUBLISH_VERSION)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
maven {
|
||||
name = "mavencentral"
|
||||
name = giteaPublish ? "gitea" : "mavencentral"
|
||||
|
||||
def releasesRepoUrl = getReleaseRepositoryUrl()
|
||||
def snapshotsRepoUrl = getSnapshotRepositoryUrl()
|
||||
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
|
||||
|
||||
credentials {
|
||||
username ossrhUsername
|
||||
password ossrhPassword
|
||||
if (giteaPublish) {
|
||||
if (!giteaToken) {
|
||||
throw new GradleException("缺少 giteaToken:请写入 ~/.gradle/gradle.properties 或设置环境变量 GITEA_TOKEN")
|
||||
}
|
||||
credentials(HttpHeaderCredentials) {
|
||||
name = "Authorization"
|
||||
value = "token ${giteaToken}"
|
||||
}
|
||||
authentication {
|
||||
header(HttpHeaderAuthentication)
|
||||
}
|
||||
} else if (!isLocal()) {
|
||||
credentials {
|
||||
username ossrhUsername
|
||||
password ossrhPassword
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
signing {
|
||||
required { !isLocal() && project.findProperty("signing.keyId") }
|
||||
required { !isLocal() && !giteaPublish && project.findProperty("signing.keyId") }
|
||||
sign publishing.publications
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user