Skip to content

Commit

Permalink
Discover Gradle builds by looking for setting.gradle(.kts)
Browse files Browse the repository at this point in the history
When the option 'gradle.nestedProjects: true' is set, the build
roots are currently discovered by looking for the wrapper scripts.
These however are completely optional for a build.

But there is one thing each Gradle build definitely needs to have:
A 'settings.gradle' or 'setting.gradle.kts' file.
Gradle itself searches for these files to accept a folder as a
Gradle build/project.

This change proposes to check for these files instead of the gradlw
scripts.

A good project to test this with is
https://github.com/microsoft/build-server-for-gradle
which contains a lot of Gradle build in the 'testProjects' folder.

Signed-off-by: Jendrik Johannes <[email protected]>
  • Loading branch information
jjohannes committed Oct 14, 2024
1 parent 9ac3ffe commit 847af34
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion extension/src/stores/RootProjectsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { RootProject } from "../rootProject/RootProject";
import { GRADLE_BUILD_FILE_NAMES } from "../constant";

async function getNestedRootProjectFolders(): Promise<string[]> {
const matchingNestedWrapperFiles = await vscode.workspace.findFiles("**/{gradlew,gradlew.bat}");
const matchingNestedWrapperFiles = await vscode.workspace.findFiles("**/{settings.gradle,settings.gradle.kts}");
return [...new Set(matchingNestedWrapperFiles.map((uri) => path.dirname(uri.fsPath)))];
}

Expand Down
4 changes: 2 additions & 2 deletions extension/src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export function waitOnTcp(host: string, port: number): Promise<void> {

export function isGradleRootProject(rootProject: RootProject): boolean {
return (
fs.existsSync(path.join(rootProject.getProjectUri().fsPath, "gradlew")) ||
fs.existsSync(path.join(rootProject.getProjectUri().fsPath, "gradlew.bat"))
fs.existsSync(path.join(rootProject.getProjectUri().fsPath, "settings.gradle")) ||
fs.existsSync(path.join(rootProject.getProjectUri().fsPath, "settings.gradle.kts"))
);
}

Expand Down

0 comments on commit 847af34

Please sign in to comment.