See #16603 for background. The actual fix will be slightly more complex as we'll need to unwrap some Gradle types.