Skip to content

Exclude generated sources in build directory from parsing#433

Merged
timtebeek merged 2 commits intomainfrom
fix-gradle-plugin-216
Apr 12, 2026
Merged

Exclude generated sources in build directory from parsing#433
timtebeek merged 2 commits intomainfrom
fix-gradle-plugin-216

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented Apr 11, 2026

Summary

  • Source directories inside the build directory (e.g. protobuf-generated Kotlin sources) are now filtered out at the directory level before file walking, preventing generated sources from being parsed and appearing in recipe results
  • Type information from generated sources remains available via compiled class files already on the classpath
  • Removed the hardcoded /protos/build/generated exclusion, now covered by the generic build directory filter
  • Consolidated duplicated isExcluded/buildDir filtering from individual parse methods (parseJavaFiles, parseKotlinFiles, inline Groovy/multiplatform blocks) into a single filter at the stream assembly point, in both DefaultProjectParser and AndroidProjectParser

Test plan

  • Existing tests pass (./gradlew :plugin:test)

Fixes #216. Source directories located inside the build directory (e.g.
protobuf-generated Kotlin sources) were being included in recipe results.
Filter them out at the directory level before file walking. Type information
from generated sources remains available via compiled class files on the
classpath. Removes the now-unnecessary hardcoded /protos/build/generated
exclusion.
@shanman190
Copy link
Copy Markdown
Collaborator

Just curious, but should isExcluded be extracted from each individual parse chain and moved toward the end of all parsing to eject any file that happens to be explicitly excluded?

Move the isExcluded and buildDir checks out of parseJavaFiles(),
parseKotlinFiles(), and the inline Groovy/multiplatform blocks into a
single filter applied when assembling the source file stream. This
removes duplicated exclusion logic and simplifies the parse method
signatures in both DefaultProjectParser and AndroidProjectParser.
@timtebeek
Copy link
Copy Markdown
Member Author

Good suggestion! Extracted the isExcluded/buildDir filtering from each individual parse method (parseJavaFiles(), parseKotlinFiles(), inline Groovy block, and multiplatform Kotlin block) into a single filter applied at the stream assembly point. This applies to both DefaultProjectParser and AndroidProjectParser.

@timtebeek timtebeek changed the title Exclude generated sources in build directory from recipe results Exclude generated sources in build directory from parsing Apr 11, 2026
@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Apr 12, 2026
@timtebeek timtebeek merged commit cd7cf82 into main Apr 12, 2026
3 of 4 checks passed
@timtebeek timtebeek deleted the fix-gradle-plugin-216 branch April 12, 2026 07:01
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Generated kotlin sources inside the build directory are showing up in recipe results

2 participants