Preserve property descriptions during Gradle incremental compilation#50489
Draft
galenzo17 wants to merge 1 commit into
Draft
Preserve property descriptions during Gradle incremental compilation#50489galenzo17 wants to merge 1 commit into
galenzo17 wants to merge 1 commit into
Conversation
Cache descriptions in a location outside CLASS_OUTPUT so that Gradle's incremental compilation does not lose javadoc-based descriptions for types passed as .class files. See spring-projectsgh-28075 Signed-off-by: Agustin Bereciartua <bereciartua.agustin@gmail.com>
9a177ef to
3baf552
Compare
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.
Status
Draft. Seeking approach validation before adding performance benchmarks
and a repro on a spring-boot-internal module. Specifically requesting
sanity-check on the
FieldValuesParserextension (the@FunctionalInterfaceremoval to add a default method).
Summary
When Gradle performs incremental compilation, unchanged
@ConfigurationPropertiesclasses are passed to the annotation processor as
.classfiles via theclassesparameter of
JavaCompiler.getTask(). Since bytecode does not carry javadoc,Elements.getDocComment()returnsnullfor these elements and their propertydescriptions are lost from
spring-configuration-metadata.json.This implements option 1 from the issue thread
(confirmed by @wilkinsona):
cache descriptions in a location outside
CLASS_OUTPUTthat Gradle does not cleanduring incremental builds.
Approach
org.springframework.boot.configurationprocessor.descriptionCacheLocationconfigures where the cache file lives (opt-in, zero behavior change when unset)
.class-backed elements are detected viacom.sun.source.util.Trees.getTree(),reusing the existing reflection wrapper in
JavaCompilerFieldValuesParser.class-backed types are filled from cache before theJSON is emitted; then the cache is replaced with the current metadata
automatically pruned — no unbounded growth
Files changed
FieldValuesParserdefault hasSourceTree()(removed@FunctionalInterface— internal API)JavaCompilerFieldValuesParserhasSourceTree()using existingTreesinstanceMetadataGenerationEnvironmenthasSourceTree()delegating to field values parserConfigurationMetadataAnnotationProcessor.class-backed types, fills missing descriptions from cache on write, then refreshes cacheDescriptionCache(new)DescriptionCacheTests(new)Tests
DescriptionCacheTests— all passspring-boot-configuration-processortests continue to passScope and limitations
spring-boot-gradle-pluginshould wire thedescriptionCacheLocationoption automaticallyAlternatives considered
ecosystem-wide migration of existing property descriptions from javadoc to a new
annotation
replace strategy is simpler and leverages the invariant that Gradle passes all
annotated types every round
See gh-28075