Skip to content

Commit

Permalink
Add the ability to deploy specific preinstrumented jars to maven
Browse files Browse the repository at this point in the history
Add support for the environment variable 'PREINSTRUMENTED_SDK_VERSIONS'
which lets you build and publish specific versions of preinstrumented
jars.

Example recent usage for the Android T jar:
PREINSTRUMENTED_SDK_VERSIONS=33 PUBLISH_PREINSTRUMENTED_JARS=true ./gradlew :preinstrumented:publish
  • Loading branch information
hoisie committed Sep 24, 2022
1 parent aff8699 commit b0645f5
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions preinstrumented/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ task instrumentAll {
doLast {
def androidAllMavenLocal = "${System.getProperty('user.home')}/.m2/repository/org/robolectric/android-all"

AndroidSdk.ALL_SDKS.each { androidSdk ->
sdksToInstrument().each { androidSdk ->
println("Instrumenting ${androidSdk.coordinates}")
def inputPath = "${androidAllMavenLocal}/${androidSdk.version}/${androidSdk.jarFileName}"
def outputPath = "${buildDir}/${androidSdk.preinstrumentedJarFileName}"
Expand Down Expand Up @@ -55,7 +55,7 @@ if (System.getenv('PUBLISH_PREINSTRUMENTED_JARS') == "true") {

publishing {
publications {
AndroidSdk.ALL_SDKS.each { androidSdk ->
sdksToInstrument().each { androidSdk ->
"sdk${androidSdk.apiLevel}"(MavenPublication) {
artifact "${buildDir}/${androidSdk.preinstrumentedJarFileName}"
artifactId 'android-all-instrumented'
Expand Down Expand Up @@ -105,14 +105,23 @@ if (System.getenv('PUBLISH_PREINSTRUMENTED_JARS') == "true") {
}

signing {
AndroidSdk.ALL_SDKS.each { androidSdk ->
sdksToInstrument().each { androidSdk ->
sign publishing.publications."sdk${androidSdk.apiLevel}"
}
}
}

def sdksToInstrument() {
var result = AndroidSdk.ALL_SDKS
var sdkFilter = (System.getenv('PREINSTRUMENTED_SDK_VERSIONS') ?: "").split(",").collect { it as Integer }
if (sdkFilter.size > 0) {
result = result.findAll { sdkFilter.contains(it.apiLevel) }
}
return result
}

clean.doFirst {
AndroidSdk.ALL_SDKS.each { androidSdk ->
delete "${buildDir}/${androidSdk.preinstrumentedJarFileName}"
}
}
}

0 comments on commit b0645f5

Please sign in to comment.