Fix consolidated license configuration cache issue

We can't do the lookup of resolvedConfiguration and artifacts in doLast

Fixes: 301571804
Change-Id: Ibb9e3eeac44f07cd8f7d03045919600c747319d2
diff --git a/d8_r8/main/build.gradle.kts b/d8_r8/main/build.gradle.kts
index 84edbbc..7ce6cc7 100644
--- a/d8_r8/main/build.gradle.kts
+++ b/d8_r8/main/build.gradle.kts
@@ -74,19 +74,19 @@
 
     val license = getRoot().resolveAll("build", "generatedLicense", "LICENSE")
     outputs.files(license)
+    val dependencies = mutableListOf<String>()
+    configurations
+      .findByName("runtimeClasspath")!!
+      .resolvedConfiguration
+      .resolvedArtifacts
+      .forEach {
+        val identifier = it.id.componentIdentifier
+        if (identifier is ModuleComponentIdentifier) {
+          dependencies.add("${identifier.group}:${identifier.module}")
+        }
+      }
 
     doLast {
-      val dependencies = mutableListOf<String>()
-      configurations
-        .findByName("runtimeClasspath")!!
-        .resolvedConfiguration
-        .resolvedArtifacts
-        .forEach {
-          val identifier = it.id.componentIdentifier
-          if (identifier is ModuleComponentIdentifier) {
-            dependencies.add("${identifier.group}:${identifier.module}")
-          }
-      }
       val libraryLicenses = libraryLicense.readText()
       dependencies.forEach {
         if (!libraryLicenses.contains("- artifact: $it")) {