Set an environment property pointing to keepanno in new gradle setup

Bug: b/270105162
Change-Id: Ie7cf61419d4c5489c50b0a3560376304aecb0bb9
diff --git a/d8_r8/commonBuildSrc/src/main/kotlin/TestConfigurationHelper.kt b/d8_r8/commonBuildSrc/src/main/kotlin/TestConfigurationHelper.kt
index 308bf71..4ca414d 100644
--- a/d8_r8/commonBuildSrc/src/main/kotlin/TestConfigurationHelper.kt
+++ b/d8_r8/commonBuildSrc/src/main/kotlin/TestConfigurationHelper.kt
@@ -72,7 +72,7 @@
       val userDefinedCoresPerFork = System.getenv("R8_GRADLE_CORES_PER_FORK")
       val processors = Runtime.getRuntime().availableProcessors()
       // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
-      if (userDefinedCoresPerFork != null) {
+      if (!userDefinedCoresPerFork.isNullOrEmpty()) {
         test.maxParallelForks = processors.div(userDefinedCoresPerFork.toInt())
       } else {
         // On work machines this seems to give the best test execution time (without freezing).
diff --git a/d8_r8/main/build.gradle.kts b/d8_r8/main/build.gradle.kts
index c829d31..207f87e 100644
--- a/d8_r8/main/build.gradle.kts
+++ b/d8_r8/main/build.gradle.kts
@@ -99,7 +99,7 @@
     val swissArmy = swissArmyKnife.get().outputs.getFiles().getSingleFile()
     val deps = depsJar.get().outputs.files.getSingleFile()
     inputs.files(listOf(swissArmy, deps))
-    val output = file(Paths.get("build", "libs", "r8-deps-relocated.jar"))
+    val output = getRoot().resolveAll("build", "libs", "r8-deps-relocated.jar")
     outputs.file(output)
     commandLine = baseCompilerCommandLine(
       swissArmy,
diff --git a/d8_r8/test_modules/tests_java_8/build.gradle.kts b/d8_r8/test_modules/tests_java_8/build.gradle.kts
index 2e6a3f1..f8ef982 100644
--- a/d8_r8/test_modules/tests_java_8/build.gradle.kts
+++ b/d8_r8/test_modules/tests_java_8/build.gradle.kts
@@ -23,10 +23,13 @@
   targetCompatibility = JavaVersion.VERSION_1_8
 }
 
+// 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 keepAnnoJarTask = projectTask("keepanno", "jar")
+val keepAnnoCompileTask = projectTask("keepanno", "compileJava")
+
 dependencies {
-  // 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.
-  implementation(projectTask("keepanno", "jar").outputs.files)
+  implementation(keepAnnoJarTask.outputs.files)
   implementation(projectTask("main", "jar").outputs.files)
   implementation(projectTask("resourceshrinker", "jar").outputs.files)
   implementation(Deps.asm)
@@ -161,21 +164,7 @@
       dependsOn(thirdPartyRuntimeInternalDependenciesTask)
     }
     dependsOn(*sourceSetDependenciesTasks)
-    println("NOTE: Number of processors " + Runtime.getRuntime().availableProcessors())
-    val userDefinedCoresPerFork = System.getenv("R8_GRADLE_CORES_PER_FORK")
-    val processors = Runtime.getRuntime().availableProcessors()
-    // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html.
-    if (!userDefinedCoresPerFork.isNullOrEmpty()) {
-      maxParallelForks = processors / userDefinedCoresPerFork.toInt()
-    } else {
-      // On normal work machines this seems to give the best test execution time (without freezing)
-      maxParallelForks = processors / 3
-      // On low cpu count machines (bots) we under subscribe, so increase the count.
-      if (processors == 8) {
-        maxParallelForks = 3
-      }
-    }
-    println("NOTE: Max parallel forks " + maxParallelForks)
+    environment.put("KEEP_ANNO_COMPILED_OUTPUT", keepAnnoCompileTask.outputs.files.getAsPath())
   }
 
   val testJar by registering(Jar::class) {