Replace JAR scanning on dependency change with a JavaSourceSet dirty flag#7460
Draft
steve-aom-elliott wants to merge 1 commit intomainfrom
Draft
Replace JAR scanning on dependency change with a JavaSourceSet dirty flag#7460steve-aom-elliott wants to merge 1 commit intomainfrom
steve-aom-elliott wants to merge 1 commit intomainfrom
Conversation
sambsnyd
approved these changes
Apr 22, 2026
af305f0 to
a93cc9d
Compare
…flag When dependency-mutating recipes (ChangeDependency, AddDependency, UpgradeDependencyVersion) run, they previously asked JavaSourceSetUpdater to download the new dependency's JAR and scan it for types so that downstream ambiguity checks (ChangePackage, ChangeType, OrderImports, AddImport) could see the post-change classpath. On large multi-module projects driven by recipes like UpgradeSpringBoot_4_0, that JAR retrieval dominates recipe wall time with a large fraction of the run's wall time spent there even after prior fetch optimizations. Introduce a `dirty` flag on the JavaSourceSet marker instead. JavaSourceSetUpdater now flips that flag on every change — no downloads, no classpath reshaping. Ambiguity-sensitive recipes read the flag and take the safe path when it is set: - ImportLayoutStyle.isPackageFoldable returns false for a dirty source set, so OrderImports never folds imports into a star it cannot prove is unambiguous. - AddImport passes the dirty flag through to the same conflict detector, so added imports are not folded either. - ChangePackage.hasAmbiguity returns true for a dirty source set, expanding a star into explicit imports before rewriting the package. - ChangeType.maybeAddExplicitImportForAmbiguity adds the explicit import unconditionally for a dirty source set. Parser-built markers are never dirty; the flag is sticky within a recipe run and cleared only by re-parsing. `withDirty(boolean)` is Lombok-generated. Tests cover the marker round-trip, the dirty-flipping in the updater, and the four consumer recipes' safe-path behavior. A new `markSourceSetDirty()` helper in rewrite-java Assertions simulates the post-dependency-change state.
a93cc9d to
cd00f8c
Compare
Contributor
Author
|
@sambsnyd Just wanted to check whether we still feel alright about this going in. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ChangeDependency,AddDependency,UpgradeDependencyVersion) run,JavaSourceSetUpdaterpreviously downloaded the new dependency's JAR and scanned it for types so that downstream ambiguity checks (ChangePackage,ChangeType,OrderImports,AddImport) could see the post-change classpath. On large multi-module projects driven by recipes likeUpgradeSpringBoot_4_0, that JAR retrieval can dominate recipe wall time - in one reference run I measured ~97s (50% of recipe time) spent there, overwhelmingly inChangeDependency, even with PRs Share artifact cache across JavaSourceSetUpdater visitors #7454 and Avoid triggering full transitive resolution from GradleDependencyConfiguration.findResolvedDependency #7455 already in place.This PR replaces the downloader with a
dirtyflag on theJavaSourceSetmarker:JavaSourceSetUpdater.{changeDependency,addDependency}now simply flip the flag - no downloads, no classpath reshaping.ImportLayoutStyle.isPackageFoldablereturnsfalse→OrderImportsnever folds a group of imports into a star it cannot prove is unambiguous.AddImportpasses the same flag through to the conflict detector.ChangePackage.hasAmbiguityreturnstrue→ an existing star import is expanded before rewriting the package.ChangeType.maybeAddExplicitImportForAmbiguityadds the explicit import unconditionally when dirty.The flag is sticky within a recipe run and cleared only by re-parsing. Parser-built markers are never dirty.
withDirty(boolean)is Lombok-generated.Safety semantics
Two simple rules replace the old classpath inspection:
Both decisions are strictly conservative with respect to the old behavior - a dirty marker never produces a result that the old classpath-based check would have forbidden.
Test plan
rewrite-java:test- passesrewrite-java-test:test- passes (new coverage:JavaSourceSetTest.withDirtyTogglesFlagWithoutOtherChanges,JavaSourceSetTest.parserBuiltSourceSetIsNotDirty,OrderImportsTest.doNotFoldIntoStarWhenSourceSetIsDirty,ChangePackageTest.changePackageExpandsStarImportWhenSourceSetIsDirty,ChangeTypeTest.changeTypeAddsExplicitImportWhenSourceSetIsDirty)rewrite-maven:test- passes (new coverage:JavaSourceSetUpdaterTestthree dirty-flipping cases;ChangeDependencyGroupIdAndArtifactIdTest.updatesJavaSourceSetMarkerOnJavaFiles+composedWithChangePackageUpdatesImportsupdated to assertisDirty() == true)rewrite-kotlin:test- passesrewrite-gradle:compileTestJava- passes