Skip to content

Commit b24937a

Browse files
authored
fix(build): declare buildMetadata's real inputs (#2095)
buildMetadata registered its compiled-class inputs only if the directories already existed at configuration time, so after rm -rf app/build it was considered UP-TO-DATE and shipped stale metadata (new classes undefined from JS); it also declared every variant's class output, which failed Gradle's implicit-dependency validation when assembling the non-selected variant. The class directories of the selected build type are now declared lazily and unconditionally, ordered after other subprojects' compile tasks. Its jar-list input pointed at a file that doesn't exist, so dependency jar changes never re-ran it; the jars named in collectAllJars' list are now fingerprinted instead of the list file the task itself appends to.
1 parent 9621d97 commit b24937a

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

‎test-app/app/build.gradle‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -966,21 +966,36 @@ task buildMetadata(type: BuildToolTask) {
966966

967967
description = "builds metadata with provided jar dependencies"
968968

969-
inputs.files("$MDG_JAVA_DEPENDENCIES")
969+
// collectAllJars rewrites this list on every build and doFirst then appends the class
970+
// directories to it, so fingerprint the jars it names rather than the file itself. Must
971+
// stay a provider: the list is only current once collectAllJars has run.
972+
def mdgJavaDependenciesFile = file("$BUILD_TOOLS_PATH/$MDG_JAVA_DEPENDENCIES")
973+
inputs.files(provider {
974+
mdgJavaDependenciesFile.exists() ? mdgJavaDependenciesFile.readLines().findAll { it.endsWith(".jar") } : []
975+
}).withPropertyName("dependencyJars")
970976

971977
// make MDG aware of whitelist.mdg and blacklist.mdg files
972978
// inputs.files(project.fileTree(dir: "$rootDir", include: "**/*.mdg"))
973979
// use explicit inputs as the above makes the whole build-tools directory an input!
974980
inputs.files("$BUILD_TOOLS_PATH/whitelist.mdg", "$BUILD_TOOLS_PATH/blacklist.mdg")
975981

976-
def classesDir = layout.buildDirectory.dir("intermediates/javac").get().asFile
977-
if (classesDir.exists()) {
978-
inputs.dir(classesDir)
979-
}
980-
981-
def kotlinClassesDir = layout.buildDirectory.dir("tmp/kotlin-classes").get().asFile
982-
if (kotlinClassesDir.exists()) {
983-
inputs.dir(kotlinClassesDir)
982+
// Must mirror the directories doFirst scans. Declared lazily because they don't exist
983+
// yet at configuration time on a clean build, and limited to the selected build type
984+
// so the other variant's compile outputs never overlap this task's inputs.
985+
def compiledClassesBuildType = project.ext.selectedBuildType
986+
inputs.files(rootProject.subprojects.collectMany { sub ->
987+
[sub.layout.buildDirectory.dir("intermediates/javac/$compiledClassesBuildType"),
988+
sub.layout.buildDirectory.dir("tmp/kotlin-classes/$compiledClassesBuildType")]
989+
}).withPropertyName("compiledClasses")
990+
991+
// This project's compile tasks are dependencies (see applicationVariants above). For
992+
// other subprojects only order after them: ones the app depends on are already reached
993+
// transitively, and a hard dependency would drag unrelated modules into the build.
994+
def compiledClassesTaskNames = ["JavaWithJavac", "Kotlin"].collect { "compile${compiledClassesBuildType.capitalize()}$it" }
995+
rootProject.subprojects.each { sub ->
996+
if (sub != project) {
997+
mustRunAfter { compiledClassesTaskNames.collect { sub.tasks.findByName(it) }.findAll { it != null } }
998+
}
984999
}
9851000

9861001
outputs.files("$METADATA_OUT_PATH/treeNodeStream.dat", "$METADATA_OUT_PATH/treeStringsStream.dat", "$METADATA_OUT_PATH/treeValueStream.dat")

0 commit comments

Comments
 (0)