plugins { id "application" } apply plugin: 'java' ext { javaMainClass = "org.robolectric.preinstrumented.JarInstrumentor" } application { mainClassName = javaMainClass } java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } dependencies { implementation libs.guava implementation project(":sandbox") implementation project(":shadows:versioning") } tasks.register('instrumentAll') { dependsOn ':prefetchSdks' dependsOn 'build' doLast { def androidAllMavenLocal = "${System.getProperty('user.home')}/.m2/repository/org/robolectric/android-all" sdksToInstrument().each { androidSdk -> println("Instrumenting ${androidSdk.coordinates}") def inputPath = "${androidAllMavenLocal}/${androidSdk.version}/${androidSdk.jarFileName}" def outputPath = "${buildDir}/${androidSdk.preinstrumentedJarFileName}" javaexec { classpath = sourceSets.main.runtimeClasspath main = javaMainClass args = [inputPath, outputPath] } } } } tasks.register('sourcesJar', Jar) { archiveClassifier = "sources" } tasks.register('javadocJar', Jar) { archiveClassifier = "javadoc" } // Avoid publishing the preinstrumented jars by default. They are published // manually when the instrumentation configuration changes to maximize gradle // and maven caching. if (System.getenv('PUBLISH_PREINSTRUMENTED_JARS') == "true") { apply plugin: 'maven-publish' apply plugin: "signing" publishing { publications { sdksToInstrument().each { androidSdk -> "sdk${androidSdk.apiLevel}"(MavenPublication) { artifact "${buildDir}/${androidSdk.preinstrumentedJarFileName}" artifactId 'android-all-instrumented' artifact sourcesJar artifact javadocJar version androidSdk.preinstrumentedVersion pom { name = "Google Android ${androidSdk.androidVersion} instrumented android-all library" description = "Google Android ${androidSdk.androidVersion} framework jars transformed with Robolectric instrumentation." url = "https://source.android.com/" inceptionYear = "2008" licenses { license { name = "Apache 2.0" url = "http://www.apache.org/licenses/LICENSE-2.0" comments = "While the EULA for the Android SDK restricts distribution of those binaries, the source code is licensed under Apache 2.0 which allows compiling binaries from source and then distributing those versions." distribution = "repo" } } scm { url = "https://android.googlesource.com/platform/manifest.git" connection = "https://android.googlesource.com/platform/manifest.git" } developers { developer { name = "The Android Open Source Projects" } } } } } } repositories { maven { url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" credentials { username = System.properties["sonatype-login"] ?: System.env['SONATYPE_LOGIN'] password = System.properties["sonatype-password"] ?: System.env['SONATYPE_PASSWORD'] } } } } signing { sdksToInstrument().each { androidSdk -> sign publishing.publications."sdk${androidSdk.apiLevel}" } } } static def sdksToInstrument() { var result = AndroidSdk.ALL_SDKS var preInstrumentedSdkVersions = (System.getenv('PREINSTRUMENTED_SDK_VERSIONS') ?: "") if (preInstrumentedSdkVersions.length() > 0) { var sdkFilter = preInstrumentedSdkVersions.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}" } }