CodeQL "Could not auto-detect a suitable build method" in CI
CodeQL needs to observe a real build of compiled languages (C/C++, C#, Java, Go, Swift) to extract a database. Autobuild scanned the checkout, could not recognize the build system, and stopped before any code was analyzed.
What this error means
The CodeQL "Autobuild" step fails with "Could not auto-detect a suitable build method" (or "Autobuild failed"). It happens for compiled languages when the project uses a build tool or layout autobuild does not recognize.
Error: Could not auto-detect a suitable build method. Please specify one manually.
See https://docs.github.com/code-security/codeql-cli for supported build modes.Common causes
Autobuild does not recognize the build system
Autobuild tries common invocations (Maven, Gradle, Make, dotnet). A non-standard layout, a monorepo subdirectory, or a custom bootstrap step means it finds nothing to run.
The compiled language needs an explicit build
Interpreted languages (JavaScript, Python, Ruby) analyze the source directly, but compiled languages must actually be built so the extractor sees the compiler invocations.
How to fix it
Replace autobuild with your real build commands
- Set the language to build mode
manualin the init step. - Remove the autobuild step and run the exact commands your project builds with.
- Run the analyze step after the build so the database is populated.
- uses: github/codeql-action/init@v3
with:
languages: java
build-mode: manual
- run: mvn -B clean compile
- uses: github/codeql-action/analyze@v3Try build-mode none for supported languages
For C# and Java, CodeQL now supports build-mode: none, which extracts without a build. Use it when your project cannot build in CI.
- uses: github/codeql-action/init@v3
with:
languages: csharp
build-mode: noneHow to prevent it
- Prefer explicit manual build steps for compiled languages instead of autobuild.
- Keep the CodeQL build commands in sync with your normal CI build.
- Use
build-mode: nonewhere the language supports it to avoid build brittleness.