diff --git a/test-app/app/build.gradle b/test-app/app/build.gradle index 9fbc263bf..d90f7ffe0 100644 --- a/test-app/app/build.gradle +++ b/test-app/app/build.gradle @@ -966,21 +966,36 @@ task buildMetadata(type: BuildToolTask) { description = "builds metadata with provided jar dependencies" - inputs.files("$MDG_JAVA_DEPENDENCIES") + // collectAllJars rewrites this list on every build and doFirst then appends the class + // directories to it, so fingerprint the jars it names rather than the file itself. Must + // stay a provider: the list is only current once collectAllJars has run. + def mdgJavaDependenciesFile = file("$BUILD_TOOLS_PATH/$MDG_JAVA_DEPENDENCIES") + inputs.files(provider { + mdgJavaDependenciesFile.exists() ? mdgJavaDependenciesFile.readLines().findAll { it.endsWith(".jar") } : [] + }).withPropertyName("dependencyJars") // make MDG aware of whitelist.mdg and blacklist.mdg files // inputs.files(project.fileTree(dir: "$rootDir", include: "**/*.mdg")) // use explicit inputs as the above makes the whole build-tools directory an input! inputs.files("$BUILD_TOOLS_PATH/whitelist.mdg", "$BUILD_TOOLS_PATH/blacklist.mdg") - def classesDir = layout.buildDirectory.dir("intermediates/javac").get().asFile - if (classesDir.exists()) { - inputs.dir(classesDir) - } - - def kotlinClassesDir = layout.buildDirectory.dir("tmp/kotlin-classes").get().asFile - if (kotlinClassesDir.exists()) { - inputs.dir(kotlinClassesDir) + // Must mirror the directories doFirst scans. Declared lazily because they don't exist + // yet at configuration time on a clean build, and limited to the selected build type + // so the other variant's compile outputs never overlap this task's inputs. + def compiledClassesBuildType = project.ext.selectedBuildType + inputs.files(rootProject.subprojects.collectMany { sub -> + [sub.layout.buildDirectory.dir("intermediates/javac/$compiledClassesBuildType"), + sub.layout.buildDirectory.dir("tmp/kotlin-classes/$compiledClassesBuildType")] + }).withPropertyName("compiledClasses") + + // This project's compile tasks are dependencies (see applicationVariants above). For + // other subprojects only order after them: ones the app depends on are already reached + // transitively, and a hard dependency would drag unrelated modules into the build. + def compiledClassesTaskNames = ["JavaWithJavac", "Kotlin"].collect { "compile${compiledClassesBuildType.capitalize()}$it" } + rootProject.subprojects.each { sub -> + if (sub != project) { + mustRunAfter { compiledClassesTaskNames.collect { sub.tasks.findByName(it) }.findAll { it != null } } + } } outputs.files("$METADATA_OUT_PATH/treeNodeStream.dat", "$METADATA_OUT_PATH/treeStringsStream.dat", "$METADATA_OUT_PATH/treeValueStream.dat")