<lambda>null1import java.net.URI 2 3 plugins { 4 alias(libs.plugins.application) 5 alias(libs.plugins.java) 6 } 7 8 val javaMainClass = "org.robolectric.preinstrumented.JarInstrumentor" 9 <lambda>null10application { mainClass.set(javaMainClass) } 11 <lambda>null12java { 13 sourceCompatibility = JavaVersion.VERSION_1_8 14 targetCompatibility = JavaVersion.VERSION_1_8 15 } 16 <lambda>null17dependencies { 18 implementation(libs.guava) 19 implementation(project(":sandbox")) 20 21 testImplementation(libs.junit4) 22 testImplementation(libs.mockito) 23 } 24 25 val instrumentAll by <lambda>null26 tasks.registering { 27 dependsOn(":prefetchSdks", "build") 28 29 doLast { 30 val androidAllMavenLocal = 31 "${System.getProperty("user.home")}/.m2/repository/org/robolectric/android-all" 32 sdksToInstrument().forEach { androidSdk -> 33 logger.debug("Instrumenting ${androidSdk.coordinates}") 34 35 val inputPath = "$androidAllMavenLocal/${androidSdk.version}/${androidSdk.jarFileName}" 36 val outputPath = 37 layout.buildDirectory.file(androidSdk.preinstrumentedJarFileName).get().asFile.path 38 39 providers 40 .javaexec { 41 classpath = sourceSets.getByName("main").runtimeClasspath 42 mainClass.set(javaMainClass) 43 args = listOf(inputPath, outputPath) 44 } 45 .result 46 .get() 47 } 48 } 49 } 50 <lambda>null51val emptySourcesJar by tasks.registering(Jar::class) { archiveClassifier.set("sources") } 52 <lambda>null53val emptyJavadocJar by tasks.registering(Jar::class) { archiveClassifier.set("javadoc") } 54 55 // Avoid publishing the preinstrumented jars by default. They are published 56 // manually when the instrumentation configuration changes to maximize Gradle 57 // and Maven caching. 58 if (System.getenv("PUBLISH_PREINSTRUMENTED_JARS") == "true") { 59 pluginManager.apply("maven-publish") 60 pluginManager.apply("signing") 61 <lambda>null62 extensions.configure<PublishingExtension> { 63 publications { 64 sdksToInstrument().forEach { androidSdk -> 65 register<MavenPublication>("sdk${androidSdk.apiLevel}") { 66 artifact( 67 layout.buildDirectory.file(androidSdk.preinstrumentedJarFileName).get().asFile.path 68 ) 69 artifactId = "android-all-instrumented" 70 artifact(emptySourcesJar) 71 artifact(emptyJavadocJar) 72 version = androidSdk.preinstrumentedVersion 73 74 pom { 75 name = "Google Android ${androidSdk.androidVersion} instrumented android-all library" 76 description = 77 "Google Android ${androidSdk.androidVersion} framework jars transformed with Robolectric instrumentation." 78 url = "https://source.android.com/" 79 inceptionYear = "2008" 80 81 licenses { 82 license { 83 name = "Apache 2.0" 84 url = "http://www.apache.org/licenses/LICENSE-2.0" 85 comments = 86 "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." 87 distribution = "repo" 88 } 89 } 90 91 scm { 92 url = "https://android.googlesource.com/platform/manifest.git" 93 connection = "https://android.googlesource.com/platform/manifest.git" 94 } 95 96 developers { developer { name = "The Android Open Source Projects" } } 97 } 98 } 99 } 100 } 101 102 repositories { 103 maven { 104 url = URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/") 105 106 credentials { 107 username = System.getProperty("sonatype-login") ?: System.getenv("SONATYPE_LOGIN") 108 password = System.getProperty("sonatype-password") ?: System.getenv("SONATYPE_PASSWORD") 109 } 110 } 111 } 112 113 project.extensions.configure<SigningExtension> { 114 // Skip signing if a signing key is not configured. 115 setRequired { hasProperty("signing.keyId") } 116 117 sdksToInstrument().forEach { androidSdk -> 118 sign(publications.getByName("sdk${androidSdk.apiLevel}")) 119 } 120 } 121 } 122 123 // Workaround for https://github.com/gradle/gradle/issues/26132 124 // For some reason, Gradle has inferred that all publishing tasks depend on all signing tasks, 125 // so we must explicitly declare this here. <lambda>null126 afterEvaluate { 127 tasks.configureEach { 128 if (name.startsWith("publishSdk")) { 129 sdksToInstrument().forEach { androidSdk -> 130 dependsOn(tasks.named("signSdk${androidSdk.apiLevel}Publication")) 131 } 132 } 133 } 134 } 135 } 136 sdksToInstrumentnull137fun sdksToInstrument(): List<AndroidSdk> { 138 val sdkFilter = 139 System.getenv("PREINSTRUMENTED_SDK_VERSIONS").orEmpty().split(',').mapNotNull { 140 it.toIntOrNull() 141 } 142 if (sdkFilter.isNotEmpty()) { 143 return AndroidSdk.ALL_SDKS.filter { it.apiLevel in sdkFilter } 144 } 145 146 return AndroidSdk.ALL_SDKS 147 } 148 <lambda>null149tasks.named("clean") { 150 doFirst { 151 AndroidSdk.ALL_SDKS.forEach { androidSdk -> 152 delete(layout.buildDirectory.file(androidSdk.preinstrumentedJarFileName)) 153 } 154 } 155 } 156