feat: support for maven publish (snapshot/release)

This commit is contained in:
Connor Tumbleson 2021-03-07 15:04:16 -05:00
parent 619c17bdb0
commit 36b59a0553
No known key found for this signature in database
GPG Key ID: C3CC0A201EC7DA75

View File

@ -31,8 +31,9 @@ plugins {
apply from: 'gradle/functions.gradle'
def apktoolversion_major = '2.5.1'
def apktoolversion_minor = 'SNAPSHOT'
group = 'org.apktool'
version = '2.5.1'
def suffix = 'SNAPSHOT'
defaultTasks 'build', 'shadowJar', 'proguard'
@ -68,25 +69,28 @@ allprojects {
gradle.startParameter.excludedTaskNames += "licenseTest"
}
def apktoolVersion = 'unspecified'
if (!('release' in gradle.startParameter.taskNames)) {
def hash = getCheckedOutGitCommitHash()
if (hash == null) {
project.ext.set("hash", "dirty")
project.ext.set("apktool_version", apktoolversion_major + "-dirty")
project.ext.set("apktool_version", version + "-dirty")
println "Building SNAPSHOT (no .git folder found)"
} else {
project.ext.set("hash", hash)
project.ext.set("apktool_version", apktoolversion_major + "-" + hash + "-SNAPSHOT")
project.ext.set("apktool_version", version + "-" + hash + "-SNAPSHOT")
apktoolVersion = version + "-dev"
println "Building SNAPSHOT (" + getCheckedOutBranch() + "): " + hash
}
} else {
project.ext.set("hash", "")
if (apktoolversion_minor.length() > 0) {
project.ext.set("apktool_version", apktoolversion_major + "-" + apktoolversion_minor)
if (suffix.length() > 0) {
project.ext.set("apktool_version", version + "-" + suffix)
} else {
project.ext.set("apktool_version", apktoolversion_major)
project.ext.set("apktool_version", version)
}
apktoolVersion = version
println "Building RELEASE (" + getCheckedOutBranch() + "): " + project.ext.apktool_version
}
@ -107,6 +111,10 @@ build.doFirst {
task release {
}
// used for publishing snapshot builds to maven.
task snapshot {
}
subprojects {
apply plugin: 'java'
@ -135,4 +143,81 @@ subprojects {
exceptionFormat = 'full'
}
}
if (project.name == 'apktool-lib') {
apply plugin: 'maven-publish'
apply plugin: 'signing'
publishing {
publications {
mavenJava(MavenPublication) {
groupId = 'org.apktool'
artifactId = project.name
version = apktoolVersion
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
pom {
name = 'Apktool'
description = 'A tool for reverse engineering Android apk files.'
url = 'https://apktool.org'
licenses {
license {
name = 'The Apache License 2.0'
url = 'https://opensource.org/licenses/Apache-2.0'
}
}
developers {
developer {
id = 'iBotPeaches'
name = 'Connor Tumbleson'
email = 'connor.tumbleson@gmail.com'
}
developer {
id = 'brutall'
name = 'Ryszard Wiśniewski'
email = 'brut.alll@gmail.com'
}
}
scm {
connection = 'scm:git:git://github.com/iBotPeaches/Apktool.git'
developerConnection = 'scm:git:git@github.com:iBotPeaches/Apktool.git'
url = 'https://ibotpeaches.github.io/Apktool'
}
}
}
}
if (rootProject.hasProperty('ossrhUsername') && rootProject.hasProperty('ossrhPassword')) {
repositories {
maven {
url = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/'
credentials {
username ossrhUsername
password ossrhPassword
}
}
}
}
}
signing {
required { gradle.taskGraph.hasTask('publish') }
sign(publishing.publications["mavenJava"])
}
java {
withJavadocJar()
withSourcesJar()
}
tasks.getByPath(':release').dependsOn(publish);
tasks.getByPath(':snapshot').dependsOn(publish);
}
}