Skip to content

Commit

Permalink
Add build.gradle.kts to Gradle executor detection (#1231)
Browse files Browse the repository at this point in the history
Most modern Gradle projects use the Gradle Kotlin DSL.
This change is necessary to detect projects as it's not possible
to add one of the existing filetypes without disrupting the build
configuration, especially in multi-project Gradle builds.

Fixes #846
  • Loading branch information
josephglanville committed May 10, 2024
1 parent 99f81ca commit 21fa48b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### Improvements

- Plugin: will now automatically use the Gradle executor if build.gradle.kts is present

### Bug Fixes
1 change: 1 addition & 0 deletions pkg/internal/executors/executor_gradle.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (gradle) isGradleProject(dir fs.FS, opts JavaExecutorOptions) (bool, error)
"settings.gradle",
"settings.gradle.kts",
"build.gradle",
"build.gradle.kts",
}
for _, p := range gradleMarkers {
isGradle, err := fsys.FileExists(dir, p)
Expand Down
22 changes: 20 additions & 2 deletions pkg/internal/executors/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func TestGradleKTS(t *testing.T) {
fsys := fsys.TestFS("app",
map[string]string{"gradle": "/usr/bin/gradle"},
fstest.MapFS{
"settings.gradle.kts": {},
"app/build.gradle": {},
"settings.gradle.kts": {},
"app/build.gradle.kts": {},
})
exec, err := NewJavaExecutor(JavaExecutorOptions{WD: fsys})
assert.NoError(t, err)
Expand Down Expand Up @@ -86,6 +86,24 @@ func TestGradleMultiProject(t *testing.T) {
exec.RunArgs)
}

func TestGradleKTSMultiProject(t *testing.T) {
fsys := fsys.TestFS("services/app-cluster",
map[string]string{"gradle": "/usr/bin/gradle"},
fstest.MapFS{
"services/app-cluster/build.gradle.kts": {},
"services/mgmt-cluster/build.gradle.kts": {},
"gradlew": {},
"settings.gradle.kts": {},
})
exec, err := NewJavaExecutor(JavaExecutorOptions{WD: fsys})
assert.NoError(t, err)
assert.Equal(t, "./gradlew", exec.Cmd)
assert.Equal(t, ".", exec.Dir)
assert.Equal(t,
[]string{":services:app-cluster:run", "--console=plain"},
exec.RunArgs)
}

func TestGradleUseExecutor(t *testing.T) {
fs := fsys.TestFS("app",
map[string]string{
Expand Down

0 comments on commit 21fa48b

Please sign in to comment.