Commit 2fda680
authored
Add Kotlin script template support for Gradle KTS (#6792)
* Add Kotlin script template support for Gradle KTS parsing
Leverage K2 FIR compiler extensions to configure implicit receivers and default
imports for build.gradle.kts and settings.gradle.kts files. This improves type
information for Gradle DSL methods, enabling better recipe matching and method
resolution. Implements FirScriptConfiguratorExtension and
FirScriptResolutionConfigurationExtension to provide Project/Settings as implicit
receivers and Gradle API packages as default imports.
* Unify Gradle recipe visitors for Groovy and Kotlin DSL
Now that Kotlin script templates provide type information for .gradle.kts
files, merge separate GroovyVisitor/KotlinVisitor pairs into single
JavaVisitor implementations where possible.
- UpdateJavaCompatibility: replace dual GroovyIsoVisitor + KotlinIsoVisitor
with a single JavaVisitor that handles both DSLs
- UpgradeTransitiveDependencyVersion: replace inline GroovyIsoVisitor and
KotlinIsoVisitor literal visitors with shared ChangeStringLiteral, and
simplify the constraints precondition check
* Fix FindRepository matching for KTS with type information
Replace MethodMatcher-based pluginManagement/buildscript detection with
simple name matching, since the synthetic class names (RewriteSettings,
RewriteGradleProject) don't match the real types resolved by the K2
compiler (org.gradle.api.initialization.Settings, org.gradle.api.Project).
* Add FIR-to-IR conversion phase to KotlinParser (#6793)
After FIR analysis, run JvmFir2IrPipelinePhase to populate the
irFile field on KotlinSource, enabling future use of IR-based
type mapping for improved Kotlin parsing.
* Unify more Gradle recipe visitors for Groovy and Kotlin DSL
Convert ChangeDependencyGroupId and ChangeDependencyArtifactId from
GroovyIsoVisitor to JavaIsoVisitor so they work with both Groovy and
Kotlin DSL build files.
* Use real Gradle API types in MethodMatcher patterns for KTS support
Update MethodMatcher patterns from synthetic Groovy template types
(RewriteGradleProject, RewriteSettings, PluginSpec, Plugin) to real
Gradle API types (org.gradle.api.Project, Settings, PluginDependenciesSpec,
PluginDependencySpec) with matchOverrides=true, enabling matching for
both Groovy DSL and Kotlin DSL scripts.
* Increase test heap to 2g for rewrite-gradle
The K2 compiler used for KTS parsing loads many JDK modules and
consumes significant memory. The default test worker heap is
insufficient, causing OutOfMemoryError on CI.
* Use regular imports in Plugin.groovy
* Restore `isKotlin` conditions in RemovePluginVisitor due to missing types
* Verify `ChangeDependencyArtifactId` works with .kts
* Verify `ChangeDependencyGroupId` works with .kts
* Verify `DependencyInsight` works with .kts
* Verify `DependencyConstraintToRule` works with .kts
* Merge Groovy/Kotlin visitors into single JavaIsoVisitor in `UpdateJavaCompatibility`1 parent d4392fc commit 2fda680
22 files changed
Lines changed: 550 additions & 171 deletions
File tree
- rewrite-gradle
- src
- main
- groovy
- java/org/openrewrite/gradle
- internal
- plugins
- search
- trait
- test/java/org/openrewrite/gradle
- plugins
- search
- rewrite-kotlin/src/main
- java/org/openrewrite/kotlin
- kotlin/org/openrewrite/kotlin/internal
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
20 | | - | |
| 23 | + | |
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
Lines changed: 17 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
27 | 25 | | |
28 | 26 | | |
| 27 | + | |
29 | 28 | | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
97 | 99 | | |
98 | | - | |
| 100 | + | |
99 | 101 | | |
100 | 102 | | |
101 | 103 | | |
| |||
Lines changed: 17 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
27 | 25 | | |
28 | 26 | | |
| 27 | + | |
29 | 28 | | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
97 | 99 | | |
98 | | - | |
| 100 | + | |
99 | 101 | | |
100 | 102 | | |
101 | 103 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
69 | 72 | | |
70 | 73 | | |
71 | 74 | | |
| |||
88 | 91 | | |
89 | 92 | | |
90 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
91 | 97 | | |
92 | 98 | | |
93 | 99 | | |
| |||
0 commit comments