From 150d5631c3f91ffe80bf72789224a929a4d76caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Kleppe-J=C3=B8rgensen?= Date: Tue, 16 Mar 2021 11:50:46 +0100 Subject: [PATCH] Add settings.gradle[.kts] to files to detect In a multi-module project it is possible to change the names of all the build files. This is for example used to make it easier to jump to the correct file in an editor, i.e. instead of having many `build.gradle.kts` files, you can have a unique name for each based on the module name. These names will be configured in a `settings.gradle[.kts]` file in the root of the project, so to support Gradle projects doing this just add these files to the list of files used for detecting a Gradle project. --- gradle/detect.go | 2 ++ gradle/detect_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/gradle/detect.go b/gradle/detect.go index 85e91bf..abd4304 100644 --- a/gradle/detect.go +++ b/gradle/detect.go @@ -36,6 +36,8 @@ func (Detect) Detect(context libcnb.DetectContext) (libcnb.DetectResult, error) files := []string{ filepath.Join(context.Application.Path, "build.gradle"), filepath.Join(context.Application.Path, "build.gradle.kts"), + filepath.Join(context.Application.Path, "settings.gradle"), + filepath.Join(context.Application.Path, "settings.gradle.kts"), } for _, file := range files { diff --git a/gradle/detect_test.go b/gradle/detect_test.go index eb8ca94..162e2a3 100644 --- a/gradle/detect_test.go +++ b/gradle/detect_test.go @@ -92,4 +92,43 @@ func testDetect(t *testing.T, context spec.G, it spec.S) { })) }) + it("passes with settings.gradle", func() { + Expect(ioutil.WriteFile(filepath.Join(ctx.Application.Path, "settings.gradle"), []byte{}, 0644)) + + Expect(detect.Detect(ctx)).To(Equal(libcnb.DetectResult{ + Pass: true, + Plans: []libcnb.BuildPlan{ + { + Provides: []libcnb.BuildPlanProvide{ + {Name: "gradle"}, + {Name: "jvm-application-package"}, + }, + Requires: []libcnb.BuildPlanRequire{ + {Name: "gradle"}, + {Name: "jdk"}, + }, + }, + }, + })) + }) + + it("passes with settings.gradle.kts", func() { + Expect(ioutil.WriteFile(filepath.Join(ctx.Application.Path, "settings.gradle.kts"), []byte{}, 0644)) + + Expect(detect.Detect(ctx)).To(Equal(libcnb.DetectResult{ + Pass: true, + Plans: []libcnb.BuildPlan{ + { + Provides: []libcnb.BuildPlanProvide{ + {Name: "gradle"}, + {Name: "jvm-application-package"}, + }, + Requires: []libcnb.BuildPlanRequire{ + {Name: "gradle"}, + {Name: "jdk"}, + }, + }, + }, + })) + }) }