| // Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file | |
| // for details. All rights reserved. Use of this source code is governed by a | |
| // BSD-style license that can be found in the LICENSE file. | |
| import org.gradle.api.JavaVersion | |
| import org.gradle.api.tasks.Copy | |
| plugins { | |
| `java-library` | |
| id("dependencies-plugin") | |
| id("r8-test-conventions") | |
| } | |
| val root = getRoot() | |
| val partialTestClassesScope = configurations.dependencyScope("partialTestClassesScope") | |
| val partialTestClassesConfig = | |
| configurations.resolvable("partialTestClassesConfig") { | |
| extendsFrom(partialTestClassesScope.get()) | |
| } | |
| java { | |
| sourceSets.test.configure { java { srcDir(root.resolveAll("src", "test", "java")) } } | |
| // We are using a new JDK to compile to an older language version, as we don't have JDK-8 for | |
| // Windows in our repo. | |
| sourceCompatibility = JavaVersion.VERSION_1_8 | |
| targetCompatibility = JavaVersion.VERSION_1_8 | |
| toolchain { languageVersion = JavaLanguageVersion.of(11) } | |
| } | |
| // If we depend on keepanno by referencing the project source outputs we get an error regarding | |
| // incompatible java class file version. By depending on the jar we circumvent that. | |
| val keepAnnoClassesScope = configurations.dependencyScope("keepAnnoClassesScope") | |
| val keepAnnoClassesConfig = | |
| configurations.resolvable("keepAnnoClassesConfig") { extendsFrom(keepAnnoClassesScope.get()) } | |
| val resourceShrinkerClassesScope = configurations.dependencyScope("resourceShrinkerClassesScope") | |
| val resourceShrinkerClassesConfig = | |
| configurations.resolvable("resourceShrinkerClassesConfig") { | |
| extendsFrom(resourceShrinkerClassesScope.get()) | |
| } | |
| val assistantClassesScope = configurations.dependencyScope("assistantClassesScope") | |
| val assistantClassesOutput = | |
| configurations.resolvable("assistantClassesOutput") { extendsFrom(assistantClassesScope.get()) } | |
| val distDepsFilesScope = configurations.dependencyScope("distDepsFilesScope") | |
| val distDepsFiles = | |
| configurations.resolvable("distDepsFiles") { extendsFrom(distDepsFilesScope.get()) } | |
| val mainClassesScope = configurations.dependencyScope("mainClassesScope") | |
| val mainClassesOutput = | |
| configurations.resolvable("mainClassesOutput") { extendsFrom(mainClassesScope.get()) } | |
| val mainResourcesScope = configurations.dependencyScope("mainResourcesScope") | |
| val mainResources = | |
| configurations.resolvable("mainResources") { extendsFrom(mainResourcesScope.get()) } | |
| val sharedDepsScope = configurations.dependencyScope("sharedDepsScope") | |
| val sharedDepsConfig = | |
| configurations.resolvable("sharedDepsConfig") { extendsFrom(sharedDepsScope.get()) } | |
| dependencies { | |
| sharedDepsScope(project(":third_party", "sharedDepsFiles")) | |
| keepAnnoClassesScope(project(":keepanno", "keepannoClasses")) | |
| assistantClassesScope(project(":assistant", "assistantJar")) | |
| distDepsFilesScope(project(":dist", "depsFiles")) | |
| mainClassesScope(project(":main", "mainClassesOutput")) | |
| mainResourcesScope(project(":main", "mainResources")) | |
| implementation(project(":assistant", "assistantJar")) | |
| implementation(project(":keepradius", "keepradiusJar")) | |
| implementation(project(":keepanno", "keepannoClasses")) | |
| implementation(project(":libanalyzer", "libanalyzer-compile-java")) | |
| implementation(project(":main", "mainClassesOutput")) | |
| implementation(project(":main", "mainResources")) | |
| resourceShrinkerClassesScope(project(":resourceshrinker", "resourceshrinkerClasses")) | |
| implementation(project(":resourceshrinker", "resourceshrinkerClasses")) | |
| implementation(project(":resourceshrinker", "resourceshrinkerDepsJar")) | |
| implementation(project(":testbase")) | |
| implementation(project(":testbase", "depsJar")) | |
| runtimeOnlyData(project(":third_party", "agsa")) | |
| runtimeOnlyData(project(":third_party", "art5_1_1")) | |
| runtimeOnlyData(project(":third_party", "artTests")) | |
| runtimeOnlyData(project(":third_party", "bookstory")) | |
| runtimeOnlyData(project(":third_party", "bundletool")) | |
| runtimeOnlyData(project(":third_party", "chrome")) | |
| runtimeOnlyData(project(":third_party", "chromeBenchmark")) | |
| runtimeOnlyData(project(":third_party", "clank")) | |
| runtimeOnlyData(project(":third_party", "compilerApi")) | |
| runtimeOnlyData(project(":third_party", "composeExamplesChangedBitwiseValuePropagation")) | |
| runtimeOnlyData(project(":third_party", "composeSamplesCrane")) | |
| runtimeOnlyData(project(":third_party", "composeSamplesJetCaster")) | |
| runtimeOnlyData(project(":third_party", "composeSamplesJetChat")) | |
| runtimeOnlyData(project(":third_party", "composeSamplesJetLagged")) | |
| runtimeOnlyData(project(":third_party", "composeSamplesJetNews")) | |
| runtimeOnlyData(project(":third_party", "composeSamplesJetSnack")) | |
| runtimeOnlyData(project(":third_party", "composeSamplesOwl")) | |
| runtimeOnlyData(project(":third_party", "composeSamplesReply")) | |
| runtimeOnlyData(project(":third_party", "dagger")) | |
| runtimeOnlyData(project(":third_party", "desugarJdkLibs11")) | |
| runtimeOnlyData(project(":third_party", "desugarLibraryRelease2_0_3")) | |
| runtimeOnlyData(project(":third_party", "examples")) | |
| runtimeOnlyData(project(":third_party", "examplesAndroidN")) | |
| runtimeOnlyData(project(":third_party", "examplesAndroidO")) | |
| runtimeOnlyData(project(":third_party", "examplesAndroidOGenerated")) | |
| runtimeOnlyData(project(":third_party", "examplesAndroidOLegacy")) | |
| runtimeOnlyData(project(":third_party", "examplesAndroidP")) | |
| runtimeOnlyData(project(":third_party", "feeder")) | |
| runtimeOnlyData(project(":third_party", "fossifyFileManager")) | |
| runtimeOnlyData(project(":third_party", "framework")) | |
| runtimeOnlyData(project(":third_party", "gmscoreLatest")) | |
| runtimeOnlyData(project(":third_party", "gmscoreV10")) | |
| runtimeOnlyData(project(":third_party", "gson")) | |
| runtimeOnlyData(project(":third_party", "guavaJre")) | |
| runtimeOnlyData(project(":third_party", "internalIssue127524985")) | |
| runtimeOnlyData(project(":third_party", "jacoco")) | |
| runtimeOnlyData(project(":third_party", "java8Runtime")) | |
| runtimeOnlyData(project(":third_party", "jdk8")) | |
| runtimeOnlyData(project(":third_party", "jdk11")) | |
| runtimeOnlyData(project(":third_party", "jdk17")) | |
| runtimeOnlyData(project(":third_party", "jdk21")) | |
| runtimeOnlyData(project(":third_party", "jdk25")) | |
| runtimeOnlyData(project(":third_party", "jdk27")) | |
| runtimeOnlyData(project(":third_party", "jdwpTests")) | |
| runtimeOnlyData(project(":third_party", "jsr223")) | |
| runtimeOnlyData(project(":third_party", "keepassdx")) | |
| runtimeOnlyData(project(":third_party", "kotlinCompiler1_3_72")) | |
| runtimeOnlyData(project(":third_party", "nest")) | |
| runtimeOnlyData(project(":third_party", "newpipe")) | |
| runtimeOnlyData(project(":third_party", "nowinandroid")) | |
| runtimeOnlyData(project(":third_party", "omninotes")) | |
| runtimeOnlyData(project(":third_party", "opentracks")) | |
| runtimeOnlyData(project(":third_party", "processKeepRulesBinaryCompatibility")) | |
| runtimeOnlyData(project(":third_party", "proguard7_0_0")) | |
| runtimeOnlyData(project(":third_party", "proguard7_7_0")) | |
| runtimeOnlyData(project(":third_party", "protoRuntimeEdition2023")) | |
| runtimeOnlyData(project(":third_party", "protoRuntimeLegacy")) | |
| runtimeOnlyData(project(":third_party", "protoTestEdition2023")) | |
| runtimeOnlyData(project(":third_party", "protoTestProto2")) | |
| runtimeOnlyData(project(":third_party", "protoTestProto3")) | |
| runtimeOnlyData(project(":third_party", "r8")) | |
| runtimeOnlyData(project(":third_party", "r8v3_2_54")) | |
| runtimeOnlyData(project(":third_party", "readyou")) | |
| runtimeOnlyData(project(":third_party", "retraceBenchmark")) | |
| runtimeOnlyData(project(":third_party", "rhino")) | |
| runtimeOnlyData(project(":third_party", "rhinoAndroid")) | |
| runtimeOnlyData(project(":third_party", "smali")) | |
| runtimeOnlyData(project(":third_party", "opensourceNewpipe")) | |
| runtimeOnlyData(project(":third_party", "signalAndroid")) | |
| runtimeOnlyData(project(":third_party", "systemUI")) | |
| runtimeOnlyData(project(":third_party", "tachiyomi")) | |
| runtimeOnlyData(project(":third_party", "tivi")) | |
| runtimeOnlyData(project(":third_party", "tusky")) | |
| runtimeOnlyData(project(":third_party", "youtube2140")) | |
| runtimeOnlyData(project(":third_party", "youtube2140D8Merge")) | |
| runtimeOnlyData(project(":testbase", "runtimeOnlyDataElements")) | |
| // For each child project, add its test classes to the test class configuration. | |
| childProjects.values.forEach { childProject -> | |
| partialTestClassesScope(project(childProject.path, "partialTestClasses")) | |
| runtimeOnlyData(project(childProject.path, "runtimeOnlyDataElements")) | |
| add("jacocoExecScope", project(childProject.path, "jacocoExecElements")) | |
| } | |
| implementation(libs.playwright) | |
| } | |
| fun testDependencies(): FileCollection { | |
| return sourceSets.test.get().compileClasspath.filter { | |
| "$it".contains("third_party") && | |
| !"$it".contains("errorprone") && | |
| !"$it".contains("third_party/gradle") | |
| } | |
| } | |
| tasks { | |
| val createArtTests = | |
| register<CreateArtTestsTask>("createArtTests") { | |
| artTestCaseDirectory = | |
| project(":third_party").tasks.named<DownloadDependency>("download_art-tests").flatMap { | |
| it.outputDir | |
| } | |
| outputDir = layout.buildDirectory.dir("generated/test/java") | |
| } | |
| java.sourceSets.test.configure { java.srcDir(createArtTests) } | |
| "compileTestJava" { | |
| dependsOn(sharedDepsConfig) | |
| dependsOn(":testbase:compileJava") | |
| } | |
| withType<JavaCompile> { | |
| dependsOn(sharedDepsConfig) | |
| dependsOn(":testbase:compileJava") | |
| } | |
| withType<JavaExec> { | |
| if (name.endsWith("main()")) { | |
| // IntelliJ pass the main execution through a stream which is | |
| // not compatible with gradle configuration cache. | |
| notCompatibleWithConfigurationCache("JavaExec created by IntelliJ") | |
| } | |
| } | |
| register<Jar>("assembleTestJar") { | |
| from(sourceSets.test.get().output) | |
| from(partialTestClassesConfig) | |
| // TODO(b/296486206): Seems like IntelliJ has a problem depending on test source sets. | |
| // Renaming | |
| // this from the default name (tests_java_8.jar) will allow IntelliJ to find the resources in | |
| // the jar and not show red underlines. However, navigation to base classes will not work. | |
| archiveFileName.set("not_named_tests_java_8.jar") | |
| } | |
| named<Copy>("processTestResources") { | |
| dependsOn(createArtTests) | |
| val r8 = "com/android/tools/r8" | |
| from(sourceSets.test.get().java.srcDirs) { | |
| include("$r8/cf/KeepDeserializeLambdaMethodTest.java") | |
| include("$r8/desugaring/interfacemethods/methodparameters/I.java") | |
| } | |
| } | |
| register<JavaExec>("generateApiAmendments") { | |
| dependsOn(partialTestClassesConfig) | |
| mainClass.set("com.android.tools.r8.androidapi.GenerateApiAmendments") | |
| classpath = sourceSets.test.get().runtimeClasspath + partialTestClassesConfig.get() | |
| // The output is deliberately not Gradle tracked since its a circular dependency. | |
| } | |
| register<JavaExec>("generateApiDatabase") { | |
| dependsOn(partialTestClassesConfig) | |
| mainClass.set("com.android.tools.r8.apimodel.AndroidApiHashingDatabaseBuilderGeneratorTest") | |
| classpath = sourceSets.test.get().runtimeClasspath + partialTestClassesConfig.get() | |
| // The output is deliberately not Gradle tracked since its a circular dependency. | |
| } | |
| } | |
| configurations.consumable("testJar") { outgoing.artifact(tasks.named("assembleTestJar")) } | |
| fun Test.setupTestTask() { | |
| TestingState.setUpTestingState(this) | |
| systemProperty( | |
| "TEST_DATA_LOCATION", | |
| project.layout.buildDirectory.dir("classes/java/test").get().toString(), | |
| ) | |
| systemProperty( | |
| "TESTBASE_DATA_LOCATION", | |
| project(":testbase") | |
| .tasks | |
| .named<JavaCompile>("compileJava") | |
| .get() | |
| .outputs | |
| .files | |
| .asPath | |
| .split(File.pathSeparator)[0], | |
| ) | |
| dependsOn(distDepsFiles) | |
| dependsOn(sharedDepsConfig) | |
| dependsOn(project(":dist").tasks.named("r8AssistantLib")) | |
| systemProperty( | |
| "BUILD_PROP_KEEPANNO_RUNTIME_PATH", | |
| extractClassesPaths("keepanno" + File.separator, keepAnnoClassesConfig.get().asPath), | |
| ) | |
| // This path is set when compiling examples jar task in DependenciesPlugin. | |
| val r8RuntimePath = | |
| project | |
| .files( | |
| mainClassesOutput, | |
| distDepsFiles, | |
| mainResources, | |
| keepAnnoClassesConfig, | |
| assistantClassesOutput, | |
| resourceShrinkerClassesConfig, | |
| ) | |
| .asPath | |
| systemProperty("BUILD_PROP_PROCESS_KEEP_RULES_RUNTIME_PATH", r8RuntimePath) | |
| systemProperty("BUILD_PROP_R8_RUNTIME_PATH", r8RuntimePath) | |
| systemProperty("R8_DEPS", distDepsFiles.get().asPath) | |
| systemProperty("com.android.tools.r8.artprofilerewritingcompletenesscheck", "true") | |
| } | |
| tasks.withType<Test> { setupTestTask() } | |
| tasks.register("testAll") { | |
| // Added child dependencies to Test directly would force all child tests to run before the | |
| // parent tests. This task runs all test tasks as siblings, allowing concurrent execution of all | |
| // tests. | |
| // Depend specifically on the "test" task by name so we don't also trigger "testCoverage". | |
| dependsOn(tasks.named("test")) | |
| childProjects.values.forEach { childProject -> dependsOn("${childProject.path}:test") } | |
| } | |
| // Setup child-project boilerplate, only requiring them to set their java source set. | |
| subprojects { | |
| apply(plugin = "java-library") | |
| apply(plugin = "dependencies-plugin") | |
| apply(plugin = "r8-test-conventions") | |
| extensions.configure<JavaPluginExtension> { | |
| sourceCompatibility = JavaVersion.VERSION_1_8 | |
| targetCompatibility = JavaVersion.VERSION_1_8 | |
| toolchain { languageVersion = JavaLanguageVersion.of(11) } | |
| } | |
| val sharedDepsScope = configurations.dependencyScope("sharedDepsScope") | |
| val sharedDepsConfig = | |
| configurations.resolvable("sharedDepsConfig") { extendsFrom(sharedDepsScope.get()) } | |
| dependencies { | |
| add(sharedDepsScope.name, project(":third_party", "sharedDepsFiles")) | |
| add("implementation", project(":main", "mainClassesOutput")) | |
| add("implementation", project(":main", "mainResources")) | |
| add("implementation", project(":keepanno", "keepannoClasses")) | |
| add("implementation", project(":testbase")) | |
| add("implementation", project(":testbase", "depsJar")) | |
| runtimeOnlyData(project(":testbase", "runtimeOnlyDataElements")) | |
| } | |
| tasks.withType<JavaCompile> { dependsOn(sharedDepsConfig) } | |
| tasks.withType<Test> { setupTestTask() } | |
| configurations.consumable("partialTestClasses") { | |
| outgoing.artifact(layout.buildDirectory.dir("classes/java/test")) { | |
| builtBy(tasks.named("compileTestJava")) | |
| } | |
| outgoing.artifact(layout.buildDirectory.dir("resources/test")) { | |
| builtBy(tasks.named("processTestResources")) | |
| } | |
| } | |
| } |