| // 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") | |
| } | |
| val root = getRoot() | |
| val partialTestClassesScope by configurations.dependencyScope("partialTestClassesScope") | |
| val partialTestClassesConfig by | |
| configurations.resolvable("partialTestClassesConfig") { extendsFrom(partialTestClassesScope) } | |
| 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 by configurations.dependencyScope("keepAnnoClassesScope") | |
| val keepAnnoClassesConfig by | |
| configurations.resolvable("keepAnnoClassesConfig") { extendsFrom(keepAnnoClassesScope) } | |
| val resourceShrinkerClassesScope by configurations.dependencyScope("resourceShrinkerClassesScope") | |
| val resourceShrinkerClassesConfig by | |
| configurations.resolvable("resourceShrinkerClassesConfig") { | |
| extendsFrom(resourceShrinkerClassesScope) | |
| } | |
| val assistantClassesScope by configurations.dependencyScope("assistantClassesScope") | |
| val assistantClassesOutput = | |
| configurations.resolvable("assistantClassesOutput") { extendsFrom(assistantClassesScope) } | |
| val distDepsFilesScope by configurations.dependencyScope("distDepsFilesScope") | |
| val distDepsFiles by configurations.resolvable("distDepsFiles") { extendsFrom(distDepsFilesScope) } | |
| val mainClassesScope by configurations.dependencyScope("mainClassesScope") | |
| val mainClassesOutput = | |
| configurations.resolvable("mainClassesOutput") { extendsFrom(mainClassesScope) } | |
| val mainResourcesScope by configurations.dependencyScope("mainResourcesScope") | |
| val mainResources = configurations.resolvable("mainResources") { extendsFrom(mainResourcesScope) } | |
| val sharedDepsScope by configurations.dependencyScope("sharedDepsScope") | |
| val sharedDepsConfig by | |
| configurations.resolvable("sharedDepsConfig") { extendsFrom(sharedDepsScope) } | |
| val sharedDepsInternalScope by configurations.dependencyScope("sharedDepsInternalScope") | |
| val sharedDepsInternalConfig by | |
| configurations.resolvable("sharedDepsInternalConfig") { extendsFrom(sharedDepsInternalScope) } | |
| dependencies { | |
| sharedDepsScope(project(":third_party", "sharedDepsFiles")) | |
| sharedDepsInternalScope(project(":third_party", "sharedDepsInternalFiles")) | |
| 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", "bookstory")) | |
| runtimeOnlyData(project(":third_party", "bundletool")) | |
| runtimeOnlyData(project(":third_party", "chromeBenchmark")) | |
| 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", "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", "gson")) | |
| runtimeOnlyData(project(":third_party", "guavaJre")) | |
| runtimeOnlyData(project(":third_party", "jacoco")) | |
| runtimeOnlyData(project(":third_party", "jdwpTests")) | |
| runtimeOnlyData(project(":third_party", "jsr223")) | |
| runtimeOnlyData(project(":third_party", "keepassdx")) | |
| 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", "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", "tivi")) | |
| runtimeOnlyData(project(":third_party", "tusky")) | |
| 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")) | |
| } | |
| 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 | |
| // 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 | |
| // The output is deliberately not Gradle tracked since its a circular dependency. | |
| } | |
| } | |
| val testJar by configurations.consumable("testJar") | |
| artifacts { add(testJar.name, 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) | |
| if (!project.hasProperty("no_internal")) { | |
| dependsOn(sharedDepsInternalConfig) | |
| } | |
| systemProperty( | |
| "BUILD_PROP_KEEPANNO_RUNTIME_PATH", | |
| extractClassesPaths("keepanno" + File.separator, keepAnnoClassesConfig.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.asPath) | |
| systemProperty("com.android.tools.r8.artprofilerewritingcompletenesscheck", "true") | |
| } | |
| tasks.withType<Test> { setupTestTask() } | |
| val testAll by | |
| 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. | |
| dependsOn(tasks.withType<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") | |
| extensions.configure<JavaPluginExtension> { | |
| sourceCompatibility = JavaVersion.VERSION_1_8 | |
| targetCompatibility = JavaVersion.VERSION_1_8 | |
| toolchain { languageVersion = JavaLanguageVersion.of(11) } | |
| } | |
| val sharedDepsScope by configurations.dependencyScope("sharedDepsScope") | |
| val sharedDepsConfig by | |
| configurations.resolvable("sharedDepsConfig") { extendsFrom(sharedDepsScope) } | |
| 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() } | |
| val partialTestClasses by configurations.consumable("partialTestClasses") | |
| artifacts { | |
| add(partialTestClasses.name, layout.buildDirectory.dir("classes/java/test")) { | |
| builtBy(tasks.named("compileTestJava")) | |
| } | |
| add(partialTestClasses.name, layout.buildDirectory.dir("resources/test")) { | |
| builtBy(tasks.named("processTestResources")) | |
| } | |
| } | |
| } |