apply plugin: 'maven-publish' apply plugin: 'signing' def PUBLISH_VERSION = '2.0.0' def PUBLISH_GROUP_ID = 'com.compdf' def PUBLISH_ARTIFACT_ID = 'compdfkit-ui' ext["signing.keyId"] = '' //签名的密钥后8位 ext["signing.password"] = '' //签名设置的密码 ext["signing.secretKeyRingFile"] = '' //生成的secring.gpg文件目录 ext["ossrhUsername"] = '' //sonatype用户名 ext["ossrhPassword"] = '' //sonatype密码 task sourceJar(type: Jar) { from android.sourceSets.main.java.srcDirs classifier "source" } File secretPropsFile = project.rootProject.file('maven.properties') if (secretPropsFile.exists()) { println "Found secret props file, loading props" Properties p = new Properties() p.load(new FileInputStream(secretPropsFile)) p.each { name, value -> ext[name] = value } } else { println "No props file, loading env vars" } afterEvaluate { publishing { publications { release(MavenPublication) { println("publish-maven Log-------> PUBLISH_GROUP_ID: $PUBLISH_GROUP_ID; PUBLISH_ARTIFACT_ID: $PUBLISH_ARTIFACT_ID; PUBLISH_VERSION: $PUBLISH_VERSION") groupId PUBLISH_GROUP_ID artifactId PUBLISH_ARTIFACT_ID version = PUBLISH_VERSION artifact("$buildDir/outputs/aar/ComPDFKit-UI.aar") // artifact(sourceJar) pom { name = PUBLISH_ARTIFACT_ID url = 'https://www.compdf.com/' description = 'ComPDFKit SDK for Android' developers { developer { id = 'compdfkit' name = 'compdfkit' //你的sonatype用户名 email = 'youna@compdf.com' //你的sonatype注册邮箱 } } licenses { license { name = 'ComPDFKit License' url = 'https://github.com/ComPDFKit/PDF-SDK-Android/blob/main/LICENSE' } } scm { connection = 'https://github.com/ComPDFKit/PDF-SDK-Android' developerConnection = 'https://github.com/ComPDFKit/PDF-SDK-Android' url = 'https://github.com/ComPDFKit/PDF-SDK-Android/tree/main' } withXml{ def dependenciesNode = asNode().appendNode('dependencies') //Iterate over the compile dependencies (we don't want the test ones), adding a node for each configurations.implementation.allDependencies.each { if(it.group != null && (it.name != null || "unspecified".equals(it.name)) && it.version != null) { def dependencyNode = dependenciesNode.appendNode('dependency') dependencyNode.appendNode('groupId', it.group) dependencyNode.appendNode('artifactId', it.name) dependencyNode.appendNode('version', it.version) } } } } } } repositories { maven { name = PUBLISH_ARTIFACT_ID def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" println("publish version:${PUBLISH_VERSION}") url = PUBLISH_VERSION.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl credentials { username ossrhUsername password ossrhPassword } } } } } signing { sign publishing.publications }