Skip to content

Commit 9e11c22

Browse files
authored
fix(manifest): detect Gradle projects by build script, not gradlew wrapper (REA-622) (#1399)
* fix(manifest): detect Gradle projects by build script, not gradlew wrapper detectManifestActions gated Gradle auto-detection on `gradlew`, so `scan create --auto-manifest` and `socket manifest auto` skipped a Gradle project that builds with `gradle` on PATH (no wrapper) — inconsistent with `socket manifest gradle`, whose bin already falls back to gradle on PATH. Detect by `build.gradle`/`build.gradle.kts` instead, mirroring `pom.xml` (Maven) and `build.sbt` (sbt). * fix(manifest): also detect Gradle by settings.gradle(.kts) A Kotlin-DSL multi-module root can have only a settings file and no root build.gradle; such a project (with a gradlew wrapper) was detected before the build-script change and would otherwise regress to undetected. settings.gradle is Gradle's build-root marker, so detect it alongside build.gradle(.kts).
1 parent 6619eae commit 9e11c22

3 files changed

Lines changed: 81 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1212
the run unless you pass `--ignore-unresolved`, so an incomplete scan can't slip
1313
by unnoticed. Benign variant-selection ambiguity stays a one-line notice.
1414

15+
### Fixed
16+
- `socket manifest auto` and `scan create --auto-manifest` now detect a Gradle
17+
project by its build files (`build.gradle`/`.kts` or `settings.gradle`/`.kts`)
18+
instead of requiring a `gradlew` wrapper, so a project that builds with
19+
`gradle` on your PATH — including a settings-only multi-module root — is no
20+
longer skipped.
21+
1522
## [1.1.135](https://github.com/SocketDev/socket-cli/releases/tag/v1.1.135) - 2026-07-01
1623

1724
### Changed

src/commands/manifest/detect-manifest-actions.mts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ export async function detectManifestActions(
7272
'notice',
7373
`[DEBUG] - gradle auto-detection is disabled in ${SOCKET_JSON}`,
7474
)
75-
} else if (existsSync(path.join(cwd, 'gradlew'))) {
75+
} else if (
76+
existsSync(path.join(cwd, 'build.gradle')) ||
77+
existsSync(path.join(cwd, 'build.gradle.kts')) ||
78+
existsSync(path.join(cwd, 'settings.gradle')) ||
79+
existsSync(path.join(cwd, 'settings.gradle.kts'))
80+
) {
81+
// Detect by build descriptor, not the `gradlew` wrapper (a project can build via
82+
// `gradle` on PATH). `settings.gradle(.kts)` covers Kotlin-DSL roots with no root build script.
7683
debugLog('notice', '[DEBUG] - Detected a gradle build file')
7784
output.gradle = true
7885
output.count += 1

src/commands/manifest/detect-manifest-actions.test.mts

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,75 @@ describe('detectManifestActions — bazel detector', () => {
6666

6767
it('co-detects bazel and gradle when both markers are present', async () => {
6868
touch(cwd, 'MODULE.bazel')
69-
touch(cwd, 'gradlew')
69+
touch(cwd, 'build.gradle')
7070
const result = await detectManifestActions(null, cwd)
7171
expect(result.bazel).toBe(true)
7272
expect(result.gradle).toBe(true)
7373
expect(result.count).toBe(2)
7474
})
7575
})
76+
77+
describe('detectManifestActions — gradle detector', () => {
78+
let cwd: string
79+
80+
beforeEach(() => {
81+
cwd = mkTmp()
82+
})
83+
84+
afterEach(() => {
85+
rmSync(cwd, { recursive: true, force: true })
86+
})
87+
88+
it('detects build.gradle', async () => {
89+
touch(cwd, 'build.gradle')
90+
const result = await detectManifestActions(null, cwd)
91+
expect(result.gradle).toBe(true)
92+
expect(result.count).toBe(1)
93+
})
94+
95+
it('detects build.gradle.kts', async () => {
96+
touch(cwd, 'build.gradle.kts')
97+
const result = await detectManifestActions(null, cwd)
98+
expect(result.gradle).toBe(true)
99+
expect(result.count).toBe(1)
100+
})
101+
102+
it('detects settings.gradle', async () => {
103+
touch(cwd, 'settings.gradle')
104+
const result = await detectManifestActions(null, cwd)
105+
expect(result.gradle).toBe(true)
106+
expect(result.count).toBe(1)
107+
})
108+
109+
it('detects a settings-only Kotlin-DSL root (settings.gradle.kts, no build.gradle)', async () => {
110+
touch(cwd, 'settings.gradle.kts')
111+
touch(cwd, 'gradlew')
112+
const result = await detectManifestActions(null, cwd)
113+
expect(result.gradle).toBe(true)
114+
})
115+
116+
it('detects a wrapper-less gradle project (build.gradle, no gradlew)', async () => {
117+
touch(cwd, 'build.gradle')
118+
const result = await detectManifestActions(null, cwd)
119+
expect(result.gradle).toBe(true)
120+
})
121+
122+
it('does not detect gradle from a gradlew wrapper alone', async () => {
123+
touch(cwd, 'gradlew')
124+
const result = await detectManifestActions(null, cwd)
125+
expect(result.gradle).toBe(false)
126+
expect(result.count).toBe(0)
127+
})
128+
129+
it('skips gradle when defaults.manifest.gradle.disabled is true', async () => {
130+
touch(cwd, 'build.gradle')
131+
const result = await detectManifestActions(
132+
{
133+
defaults: { manifest: { gradle: { disabled: true } } },
134+
} as SocketJson,
135+
cwd,
136+
)
137+
expect(result.gradle).toBe(false)
138+
expect(result.count).toBe(0)
139+
})
140+
})

0 commit comments

Comments
 (0)