Authoritative Gradle Build Execution, Testing & Project Introspection
Executes builds, runs tests with high-precision filtering, introspects project structure, and diagnoses failures using managed orchestration and structured diagnostics.
Constitution
- ALWAYS use the
gradle tool instead of ./gradlew via shell.
- ALWAYS provide absolute paths for
projectRoot.
- ALWAYS prefer foreground execution (default) unless the task is persistent (e.g., servers) or extremely long-running (>2 minutes), or you explicitly intend to perform independent research while it proceeds.
- ALWAYS use
captureTaskOutput when you need the isolated output of a specific task (e.g., help, projects, tasks, properties, dependencies).
- STRONGLY PREFERRED: Use
query_build for all diagnostics. It is more token-efficient than reading raw console logs and provides structured access to failures, problems, and per-test output.
- ALWAYS use
query_build with kind="TESTS" and query="FullTestName" to access full test output and stack traces.
- NEVER use
taskPath or captureTaskOutput to investigate specific test failures; these provide the overall task log which is often truncated and lacks per-test isolation. Per-test output (via query) is authoritative and includes
full stack traces.
- NEVER use
--rerun-tasks unless investigating project-wide cache-specific corruption; prefer --rerun for individual tasks.
- NEVER guess task names or options; use the
help --task <name> command for authoritative documentation.
- NEVER leave background builds running; use
stopBuildId to release resources when finished.
- ALWAYS prefer Kotlin DSL (
.kts) unless the project explicitly uses Groovy.
- ALWAYS use lazy APIs (e.g.,
tasks.register<MyTask>("myTask")) instead of eager APIs (e.g., tasks.create<MyTask>("myTask")) to maintain configuration performance.
- ALWAYS use version catalogs (
libs.versions.toml) for dependency management when present.
- ALWAYS use
gradle_docs for authoritative documentation lookup instead of generic web searches.
- ALWAYS check for existing conventions in the current project before proposing changes.
- ALWAYS use safe navigation (
?.url?.toString()) and provide fallback values when accessing ArtifactRepository URLs in Gradle init scripts or plugins to prevent NullPointerException.
- ALWAYS use
:properties --property <name> for surgical property extraction.
Directives
Authoritative Task Path Syntax
Gradle uses two ways to identify tasks from the command line. Precision prevents running redundant tasks in multi-project builds.
Task Selectors (Recursive Execution)
Providing a task name without a leading colon (e.g., test, build) acts as a selector. Gradle executes that task in every project (root and all subprojects) that contains a task with that name.
- Example:
gradle(commandLine=["test"]) -> Executes test in all projects.
Absolute Task Paths (Targeted Execution)
Providing a task path with a leading colon (e.g., :test, :app:test) targets a single specific project.
- Root Project Only: Use a single leading colon.
gradle(commandLine=[":test"]) -> Root project ONLY.
- Subproject Only: Use the subproject name(s) separated by colons.
gradle(commandLine=[":app:test"]) -> ':app' subproject ONLY.
Authoritative Test Selection (--tests)
The --tests flag supports powerful, high-precision filtering:
- Exact Class:
--tests com.example.MyTest
- Exact Method:
--tests com.example.MyTest.myTestMethod
- Wildcard Method:
--tests com.example.MyTest.test* (All methods starting with 'test')
- Package Filter:
--tests com.example.service.* (All tests in the 'service' package)
- Class Prefix:
--tests *IntegrationTest (All classes ending in 'IntegrationTest')
- Character Wildcard:
--tests com.example.Test? (Matches Test1, TestA, etc.)
- Multi-Filter:
gradle(commandLine=["test", "--tests", "ClassA", "--tests", "ClassB"])
Patterns match against the fully qualified name of the test class or method.
Foreground vs. Background Execution
- ALWAYS use foreground for authoritative runs: If you intend to wait for a result, ALWAYS use foreground execution. It provides superior progressive disclosure and simpler control flow.
- Background ONLY for persistent tasks: Use
background: true ONLY for tasks that must remain active (e.g., bootRun, continuous builds) or when you intentionally intend to perform independent research while the build proceeds.
- Foreground is safe: Do not fear running high-output suites in the foreground. The
gradle tool uses progressive disclosure to provide concise summaries and structured results, keeping session history clean.
captureTaskOutput Usage
Use captureTaskOutput when you need clean, isolated output from a specific task without Gradle's general console noise. This is ideal for introspection tasks:
captureTaskOutput: ":projects" - Clean project list
captureTaskOutput: ":app:tasks" - Task list for a specific project
captureTaskOutput: ":help" - Documentation for a specific task
captureTaskOutput: ":properties" - Single property extraction
captureTaskOutput: ":app:dependencyInsight" - Dependency resolution path
gradle_docs Tag Syntax
Use gradle_docs for authoritative documentation. Always scope with tags:
| Tag |
Section |
tag:userguide |
Official Gradle User Guide |
tag:dsl |
Gradle DSL Reference (Groovy and Kotlin DSL) |
tag:javadoc |
Gradle Java API Reference |
tag:samples |
Official Gradle samples and examples |
tag:release-notes |
Version-specific release insights |
tag:best-practices |
Official best practices and performance guidelines |
Explore sections with path=".". Search scoped with tag:<section> <term>.
Idiomatic DSL Patterns
- Prefer
register over create (Lazy APIs): Use tasks.register<MyTask>("myTask") to avoid eager task configuration.
- Use Type-Safe Accessors: Prefer
tasks.test { ... } or tasks.named<Test>("test") { ... } over tasks.getByName("test").
- Use Lazy Properties: Employ
Property<T> and Provider<T> APIs for late binding and configuration cache compatibility.
- Use Version Catalogs: Centralize dependencies in
gradle/libs.versions.toml.
- Avoid
allprojects/subprojects: These blocks create tight coupling; use convention plugins and apply them selectively.
- Enable Configuration Cache: Ensure build logic avoids accessing the
Project object inside task actions.
- Use Specific Annotations: Properly label task properties with
@Input, @OutputFiles, @Internal, etc.
- Minimize Logic in Build Scripts: Move complex logic into convention plugins or
build-logic.
Resource Management
- Use
query_build() without arguments to view the build dashboard and ensure no orphaned background builds are consuming system resources.
- Set
invocationArguments: { envSource: "SHELL" } if Gradle cannot find expected env vars (e.g., JAVA_HOME).
Diagnostic Inspection (See References)
For comprehensive guidance on using query_build and wait_build for diagnostics, including JSON examples for every inspection mode (DASHBOARD, SUMMARY, FAILURES, PROBLEMS, TASKS, TESTS, CONSOLE, PROGRESS), refer
to: query_build Diagnostics Reference.
Workflows
Running a Foreground Build
- Identify the task(s) to run (e.g.,
["clean", "build"]).
- Call
gradle(commandLine=["...", "..."]).
- If the build fails, the tool returns a high-signal failure summary. Use
query_build with the buildId for deeper diagnostics via query_build Diagnostics Reference.
Running Specific Tests
- Identify the project path (e.g.,
:app) and the test filter (e.g., com.example.MyTestClass*).
- Call
gradle(commandLine=[":app:test", "--tests", "com.example.MyTest"]).
- If failures are reported, use
query_build to get detailed test output.
Orchestrating Background Jobs
- Start the build with
background: true to receive a BuildId.
- Use
wait_build(buildId=ID, timeout=..., waitFor=...) to block until a specific state or log pattern is reached.
- Use
query_build() (no arguments) to manage active jobs in the dashboard.
- Stop the job using
gradle(stopBuildId=ID) when finished.
Introspecting Project Structure
- Run
gradle(commandLine=[":projects"], captureTaskOutput=":projects") to map the multi-project hierarchy.
- Run
gradle(commandLine=[":app:tasks", "--all"], captureTaskOutput=":app:tasks") to discover runnable tasks.
- Run
gradle(commandLine=[":help", "--task", "test"], captureTaskOutput=":help") for task-specific documentation.
- Run
gradle(commandLine=[":properties", "--property", "version"], captureTaskOutput=":properties") for surgical property extraction.
- For detailed dependency resolution paths:
gradle(commandLine=[":app:dependencyInsight", "--dependency", "slf4j-api", "--configuration", "compileClasspath"], captureTaskOutput=":app:dependencyInsight").
Creating a New Module
- Map the project structure:
gradle(commandLine=[":projects"], captureTaskOutput=":projects") to find the correct parent path.
- Create directory structure:
New-Item -ItemType Directory -Force -Path "<module-name>/src/main/kotlin".
- Add to
settings.gradle.kts: Append include(":<module-name>").
- Create
build.gradle.kts with idiomatic patterns (apply convention plugins, set up standard configuration).
- Verify:
gradle(commandLine=[":<module-name>:tasks"], captureTaskOutput=":<module-name>:tasks").
Performance Audit
- Check configuration cache status:
gradle(commandLine=[":help", "--configuration-cache"]).
- Analyze task compatibility and identify violations.
- Propose fixes: migrate to lazy APIs (
Property<T>, Provider<T>) or use @Internal/@Input annotations correctly.
- Verify against latest guidance:
gradle_docs(query="tag:best-practices", projectRoot="/path/to/project").
Documentation Research
- Search the user guide:
gradle_docs(query="tag:userguide <term>", projectRoot="/path/to/project").
- Navigate the DSL reference:
gradle_docs(path="dsl/org.gradle.api.Project.html", projectRoot="/path/to/project").
- Check for breaking changes:
gradle_docs(query="tag:release-notes", version="8.6").
- Find best practices:
gradle_docs(query="tag:best-practices dependency management", projectRoot="/path/to/project").
- Search for samples:
gradle_docs(query="tag:samples toolchains", projectRoot="/path/to/project").
- Search javadocs:
gradle_docs(query="tag:javadoc Project", projectRoot="/path/to/project").
Investigating Test Failures
- Identify the
BuildId from the build result.
- Use
query_build(buildId=ID, kind="TESTS", outcome="FAILED") to list all failed tests.
- Use
query_build(buildId=ID, kind="TESTS", query=TNAME) to see the full output and stack trace for a specific test.
- DO NOT use
taskPath or captureTaskOutput for test failure investigation.
When to Use
- Core Lifecycle Execution: When you need to execute standard Gradle tasks (
build, assemble, clean) with reliable, parseable output.
- Test Execution & Diagnostics: When running tests with
--tests filtering, isolating failures, or retrieving full stack traces.
- Introspection & Mapping: When mapping multi-module project hierarchies, discovering runnable tasks, or auditing build configuration.
- Surgical Property Inspection: When extracting a specific property value (artifact version, build directory) for use in a subsequent task.
- Persistent Development Processes: When starting dev servers (
bootRun) or continuous builds where background management is required.
- Task-Specific Information Retrieval: When you need isolated output from a single task (
help, projects, tasks) without build noise.
- Build Failure Diagnostics: When performing deep-dive analysis of task failures, problems, or compilation errors.
- New Module Creation: When adding a new project or module to a multi-project build.
- Build Logic Refactoring: When cleaning up complex build scripts or creating convention plugins.
- Performance Troubleshooting: When builds are slow or failing during the configuration phase.
- Documentation & DSL Research: When looking up official Gradle syntax, user guide topics, or release notes.
Examples
Run build in all projects
Tool: gradle
{
"commandLine": ["build"]
}
// Reasoning: Task selector (no colon) verifies build health across the entire multi-project structure.
Run a single test class in a specific subproject
Tool: gradle
{
"commandLine": [":app:test", "--tests", "com.example.service.MyServiceTest"]
}
// Reasoning: Absolute task path with exact class filter for the fastest possible feedback loop.
Inspect help output for a specific task
Tool: gradle
{
"commandLine": [":app:help", "--task", "test"],
"captureTaskOutput": ":app:help"
}
// Reasoning: Using captureTaskOutput to retrieve clean, isolated documentation.
List all sub-projects in the build
Tool: gradle
{
"commandLine": [":projects"],
"captureTaskOutput": ":projects"
}
// Reasoning: Using captureTaskOutput to retrieve the project hierarchy list without startup noise.
Surgically inspect the 'version' property
Tool: gradle
{
"commandLine": [":properties", "--property", "version"],
"captureTaskOutput": ":properties"
}
// Reasoning: Using --property to isolate a single value and avoid retrieving thousands of unrelated properties.
Analyze a specific dependency conflict
Tool: gradle
{
"commandLine": [
":app:dependencyInsight",
"--dependency",
"com.google.guava:guava",
"--configuration",
"runtimeClasspath"
],
"captureTaskOutput": ":app:dependencyInsight"
}
// Reasoning: Using dependencyInsight to isolate the resolution path for a specific artifact.
Start a dev server and wait for readiness
Tool: gradle
// Step 1: Start the server in the background
{
"commandLine": [":app:bootRun"],
"background": true
}
// Response: { "buildId": "build_123" }
// Step 2: Wait for readiness signal
{
"buildId": "build_123",
"timeout": 60,
"waitFor": "Started Application"
}
// Reasoning: Background orchestration allows the server to remain active while waiting for readiness.
Search official Gradle documentation
Tool: gradle_docs
{
"query": "tag:dsl signing plugin",
"projectRoot": "/absolute/path/to/project"
}
// Reasoning: Using the DSL tag to find authoritative syntax for the signing plugin configuration.
Create a new sub-project module
Tool: run_shell_command
{
"command": "New-Item -ItemType Directory -Force -Path subproject/src/main/kotlin"
}
// Reasoning: Creating the standard directory structure for a Kotlin JVM project using correct PowerShell syntax.
List all failed tests in a build
Tool: query_build
{
"buildId": "build_abc123",
"kind": "TESTS",
"outcome": "FAILED"
}
// Reasoning: Isolating only the failures from a large test suite for efficient triage.
Troubleshooting
- Build Not Found: If a
BuildId is not recognized, it may have expired from the recent history cache. Check the dashboard (query_build()) for valid active and historical IDs.
- Task Output Not Captured: Ensure the path provided to
captureTaskOutput matches exactly one of the tasks in the commandLine.
- Missing environment variables: Set
invocationArguments: { envSource: "SHELL" } if Gradle cannot find expected env vars (e.g., JAVA_HOME).
Resources
- query_build Diagnostics Reference — Complete diagnostic patterns for DASHBOARD, SUMMARY, FAILURES, PROBLEMS, TASKS, TESTS, CONSOLE, and PROGRESS.
- Background Monitoring Patterns
- Authoritative Diagnostic Tasks — Built-in introspection tasks.
- Best Practices Snapshot — High-level best practices; always verify with
gradle_docs.
- Common Build Patterns — Idiomatic patterns for multi-project builds, convention plugins, and task registration.
- Official Gradle Documentation Research — Guidance on using
gradle_docs for authoritative documentation.
1---
2name: gradle
3description: >
4 Provides authoritative guidance for ALL Gradle operations: executing builds, running tests with surgical filtering, introspecting project structure, creating modules, and diagnosing failures;
5 ALWAYS use instead of raw shell `./gradlew` for build execution, test runs, task introspection, module creation, performance audits, and documentation research.
6 Do NOT use for dependency graph auditing/updates (use `managing_gradle_dependencies`) or dependency/plugin/Gradle source exploration (use `exploring_dependency_sources`).
7license: Apache-2.0
8metadata:
9 source: https://skillmd.com/skills/aibot88/gradle
10 author: https://github.com/rnett/gradle-mcp
11 version: "4.0"
12---
13
14# Authoritative Gradle Build Execution, Testing & Project Introspection
15
16Executes builds, runs tests with high-precision filtering, introspects project structure, and diagnoses failures using managed orchestration and structured diagnostics.
17
18## Constitution
19
20- **ALWAYS** use the `gradle` tool instead of `./gradlew` via shell.
21- **ALWAYS** provide absolute paths for `projectRoot`.
22- **ALWAYS** prefer foreground execution (default) unless the task is persistent (e.g., servers) or extremely long-running (>2 minutes), or you explicitly intend to perform independent research while it proceeds.
23- **ALWAYS** use `captureTaskOutput` when you need the isolated output of a specific task (e.g., `help`, `projects`, `tasks`, `properties`, `dependencies`).
24- **STRONGLY PREFERRED**: Use `query_build` for all diagnostics. It is more token-efficient than reading raw console logs and provides structured access to failures, problems, and per-test output.
25- **ALWAYS** use `query_build` with `kind="TESTS"` and `query="FullTestName"` to access full test output and stack traces.
26- **NEVER** use `taskPath` or `captureTaskOutput` to investigate specific test failures; these provide the overall task log which is often truncated and lacks per-test isolation. Per-test output (via `query`) is authoritative and includes
27 full stack traces.
28- **NEVER** use `--rerun-tasks` unless investigating project-wide cache-specific corruption; prefer `--rerun` for individual tasks.
29- **NEVER** guess task names or options; use the `help --task <name>` command for authoritative documentation.
30- **NEVER** leave background builds running; use `stopBuildId` to release resources when finished.
31- **ALWAYS** prefer Kotlin DSL (`.kts`) unless the project explicitly uses Groovy.
32- **ALWAYS** use lazy APIs (e.g., `tasks.register<MyTask>("myTask")`) instead of eager APIs (e.g., `tasks.create<MyTask>("myTask")`) to maintain configuration performance.
33- **ALWAYS** use version catalogs (`libs.versions.toml`) for dependency management when present.
34- **ALWAYS** use `gradle_docs` for authoritative documentation lookup instead of generic web searches.
35- **ALWAYS** check for existing conventions in the current project before proposing changes.
36- **ALWAYS** use safe navigation (`?.url?.toString()`) and provide fallback values when accessing `ArtifactRepository` URLs in Gradle init scripts or plugins to prevent `NullPointerException`.
37- **ALWAYS** use `:properties --property <name>` for surgical property extraction.
38
39## Directives
40
41### Authoritative Task Path Syntax
42
43Gradle uses two ways to identify tasks from the command line. Precision prevents running redundant tasks in multi-project builds.
44
45#### Task Selectors (Recursive Execution)
46
47Providing a task name **without a leading colon** (e.g., `test`, `build`) acts as a selector. Gradle executes that task in **every project** (root and all subprojects) that contains a task with that name.
48
49- **Example**: `gradle(commandLine=["test"])` -> Executes `test` in **all** projects.
50
51#### Absolute Task Paths (Targeted Execution)
52
53Providing a task path **with a leading colon** (e.g., `:test`, `:app:test`) targets a **single specific project**.
54
55- **Root Project Only**: Use a single leading colon. `gradle(commandLine=[":test"])` -> Root project ONLY.
56- **Subproject Only**: Use the subproject name(s) separated by colons. `gradle(commandLine=[":app:test"])` -> ':app' subproject ONLY.
57
58### Authoritative Test Selection (`--tests`)
59
60The `--tests` flag supports powerful, high-precision filtering:
61
62- **Exact Class**: `--tests com.example.MyTest`
63- **Exact Method**: `--tests com.example.MyTest.myTestMethod`
64- **Wildcard Method**: `--tests com.example.MyTest.test*` (All methods starting with 'test')
65- **Package Filter**: `--tests com.example.service.*` (All tests in the 'service' package)
66- **Class Prefix**: `--tests *IntegrationTest` (All classes ending in 'IntegrationTest')
67- **Character Wildcard**: `--tests com.example.Test?` (Matches Test1, TestA, etc.)
68- **Multi-Filter**: `gradle(commandLine=["test", "--tests", "ClassA", "--tests", "ClassB"])`
69
70Patterns match against the **fully qualified name** of the test class or method.
71
72### Foreground vs. Background Execution
73
74- **ALWAYS use foreground for authoritative runs**: If you intend to wait for a result, ALWAYS use foreground execution. It provides superior progressive disclosure and simpler control flow.
75- **Background ONLY for persistent tasks**: Use `background: true` ONLY for tasks that must remain active (e.g., `bootRun`, continuous builds) or when you intentionally intend to perform independent research while the build proceeds.
76- **Foreground is safe**: Do not fear running high-output suites in the foreground. The `gradle` tool uses progressive disclosure to provide concise summaries and structured results, keeping session history clean.
77
78### `captureTaskOutput` Usage
79
80Use `captureTaskOutput` when you need clean, isolated output from a specific task without Gradle's general console noise. This is ideal for introspection tasks:
81
82- `captureTaskOutput: ":projects"` - Clean project list
83- `captureTaskOutput: ":app:tasks"` - Task list for a specific project
84- `captureTaskOutput: ":help"` - Documentation for a specific task
85- `captureTaskOutput: ":properties"` - Single property extraction
86- `captureTaskOutput: ":app:dependencyInsight"` - Dependency resolution path
87
88### `gradle_docs` Tag Syntax
89
90Use `gradle_docs` for authoritative documentation. Always scope with tags:
91
92| Tag | Section |
93|----------------------|----------------------------------------------------|
94| `tag:userguide` | Official Gradle User Guide |
95| `tag:dsl` | Gradle DSL Reference (Groovy and Kotlin DSL) |
96| `tag:javadoc` | Gradle Java API Reference |
97| `tag:samples` | Official Gradle samples and examples |
98| `tag:release-notes` | Version-specific release insights |
99| `tag:best-practices` | Official best practices and performance guidelines |
100
101Explore sections with `path="."`. Search scoped with `tag:<section> <term>`.
102
103### Idiomatic DSL Patterns
104
105- **Prefer `register` over `create` (Lazy APIs)**: Use `tasks.register<MyTask>("myTask")` to avoid eager task configuration.
106- **Use Type-Safe Accessors**: Prefer `tasks.test { ... }` or `tasks.named<Test>("test") { ... }` over `tasks.getByName("test")`.
107- **Use Lazy Properties**: Employ `Property<T>` and `Provider<T>` APIs for late binding and configuration cache compatibility.
108- **Use Version Catalogs**: Centralize dependencies in `gradle/libs.versions.toml`.
109- **Avoid `allprojects`/`subprojects`**: These blocks create tight coupling; use convention plugins and apply them selectively.
110- **Enable Configuration Cache**: Ensure build logic avoids accessing the `Project` object inside task actions.
111- **Use Specific Annotations**: Properly label task properties with `@Input`, `@OutputFiles`, `@Internal`, etc.
112- **Minimize Logic in Build Scripts**: Move complex logic into convention plugins or `build-logic`.
113
114### Resource Management
115
116- Use `query_build()` without arguments to view the build dashboard and ensure no orphaned background builds are consuming system resources.
117- Set `invocationArguments: { envSource: "SHELL" }` if Gradle cannot find expected env vars (e.g., `JAVA_HOME`).
118
119### Diagnostic Inspection (See References)
120
121For comprehensive guidance on using `query_build` and `wait_build` for diagnostics, including JSON examples for every inspection mode (DASHBOARD, SUMMARY, FAILURES, PROBLEMS, TASKS, TESTS, CONSOLE, PROGRESS), refer
122to: [query_build Diagnostics Reference](references/query_build_diagnostics.md).
123
124## Workflows
125
126### Running a Foreground Build
127
1281. Identify the task(s) to run (e.g., `["clean", "build"]`).
1292. Call `gradle(commandLine=["...", "..."])`.
1303. If the build fails, the tool returns a high-signal failure summary. Use `query_build` with the `buildId` for deeper diagnostics via [query_build Diagnostics Reference](references/query_build_diagnostics.md).
131
132### Running Specific Tests
133
1341. Identify the project path (e.g., `:app`) and the test filter (e.g., `com.example.MyTestClass*`).
1352. Call `gradle(commandLine=[":app:test", "--tests", "com.example.MyTest"])`.
1363. If failures are reported, use `query_build` to get detailed test output.
137
138### Orchestrating Background Jobs
139
1401. Start the build with `background: true` to receive a `BuildId`.
1412. Use `wait_build(buildId=ID, timeout=..., waitFor=...)` to block until a specific state or log pattern is reached.
1423. Use `query_build()` (no arguments) to manage active jobs in the dashboard.
1434. Stop the job using `gradle(stopBuildId=ID)` when finished.
144
145### Introspecting Project Structure
146
1471. Run `gradle(commandLine=[":projects"], captureTaskOutput=":projects")` to map the multi-project hierarchy.
1482. Run `gradle(commandLine=[":app:tasks", "--all"], captureTaskOutput=":app:tasks")` to discover runnable tasks.
1493. Run `gradle(commandLine=[":help", "--task", "test"], captureTaskOutput=":help")` for task-specific documentation.
1504. Run `gradle(commandLine=[":properties", "--property", "version"], captureTaskOutput=":properties")` for surgical property extraction.
1515. For detailed dependency resolution paths: `gradle(commandLine=[":app:dependencyInsight", "--dependency", "slf4j-api", "--configuration", "compileClasspath"], captureTaskOutput=":app:dependencyInsight")`.
152
153### Creating a New Module
154
1551. Map the project structure: `gradle(commandLine=[":projects"], captureTaskOutput=":projects")` to find the correct parent path.
1562. Create directory structure: `New-Item -ItemType Directory -Force -Path "<module-name>/src/main/kotlin"`.
1573. Add to `settings.gradle.kts`: Append `include(":<module-name>")`.
1584. Create `build.gradle.kts` with idiomatic patterns (apply convention plugins, set up standard configuration).
1595. Verify: `gradle(commandLine=[":<module-name>:tasks"], captureTaskOutput=":<module-name>:tasks")`.
160
161### Performance Audit
162
1631. Check configuration cache status: `gradle(commandLine=[":help", "--configuration-cache"])`.
1642. Analyze task compatibility and identify violations.
1653. Propose fixes: migrate to lazy APIs (`Property<T>`, `Provider<T>`) or use `@Internal`/`@Input` annotations correctly.
1664. Verify against latest guidance: `gradle_docs(query="tag:best-practices", projectRoot="/path/to/project")`.
167
168### Documentation Research
169
1701. Search the user guide: `gradle_docs(query="tag:userguide <term>", projectRoot="/path/to/project")`.
1712. Navigate the DSL reference: `gradle_docs(path="dsl/org.gradle.api.Project.html", projectRoot="/path/to/project")`.
1723. Check for breaking changes: `gradle_docs(query="tag:release-notes", version="8.6")`.
1734. Find best practices: `gradle_docs(query="tag:best-practices dependency management", projectRoot="/path/to/project")`.
1745. Search for samples: `gradle_docs(query="tag:samples toolchains", projectRoot="/path/to/project")`.
1756. Search javadocs: `gradle_docs(query="tag:javadoc Project", projectRoot="/path/to/project")`.
176
177### Investigating Test Failures
178
1791. Identify the `BuildId` from the build result.
1802. Use `query_build(buildId=ID, kind="TESTS", outcome="FAILED")` to list all failed tests.
1813. Use `query_build(buildId=ID, kind="TESTS", query=TNAME)` to see the full output and stack trace for a specific test.
1824. **DO NOT** use `taskPath` or `captureTaskOutput` for test failure investigation.
183
184## When to Use
185
186- **Core Lifecycle Execution**: When you need to execute standard Gradle tasks (`build`, `assemble`, `clean`) with reliable, parseable output.
187- **Test Execution & Diagnostics**: When running tests with `--tests` filtering, isolating failures, or retrieving full stack traces.
188- **Introspection & Mapping**: When mapping multi-module project hierarchies, discovering runnable tasks, or auditing build configuration.
189- **Surgical Property Inspection**: When extracting a specific property value (artifact version, build directory) for use in a subsequent task.
190- **Persistent Development Processes**: When starting dev servers (`bootRun`) or continuous builds where background management is required.
191- **Task-Specific Information Retrieval**: When you need isolated output from a single task (`help`, `projects`, `tasks`) without build noise.
192- **Build Failure Diagnostics**: When performing deep-dive analysis of task failures, problems, or compilation errors.
193- **New Module Creation**: When adding a new project or module to a multi-project build.
194- **Build Logic Refactoring**: When cleaning up complex build scripts or creating convention plugins.
195- **Performance Troubleshooting**: When builds are slow or failing during the configuration phase.
196- **Documentation & DSL Research**: When looking up official Gradle syntax, user guide topics, or release notes.
197
198## Examples
199
200### Run build in all projects
201
202Tool: `gradle`
203
204```json
205{
206 "commandLine": ["build"]
207}
208// Reasoning: Task selector (no colon) verifies build health across the entire multi-project structure.
209```
210
211### Run a single test class in a specific subproject
212
213Tool: `gradle`
214
215```json
216{
217 "commandLine": [":app:test", "--tests", "com.example.service.MyServiceTest"]
218}
219// Reasoning: Absolute task path with exact class filter for the fastest possible feedback loop.
220```
221
222### Inspect help output for a specific task
223
224Tool: `gradle`
225
226```json
227{
228 "commandLine": [":app:help", "--task", "test"],
229 "captureTaskOutput": ":app:help"
230}
231// Reasoning: Using captureTaskOutput to retrieve clean, isolated documentation.
232```
233
234### List all sub-projects in the build
235
236Tool: `gradle`
237
238```json
239{
240 "commandLine": [":projects"],
241 "captureTaskOutput": ":projects"
242}
243// Reasoning: Using captureTaskOutput to retrieve the project hierarchy list without startup noise.
244```
245
246### Surgically inspect the 'version' property
247
248Tool: `gradle`
249
250```json
251{
252 "commandLine": [":properties", "--property", "version"],
253 "captureTaskOutput": ":properties"
254}
255// Reasoning: Using --property to isolate a single value and avoid retrieving thousands of unrelated properties.
256```
257
258### Analyze a specific dependency conflict
259
260Tool: `gradle`
261
262```json
263{
264 "commandLine": [
265 ":app:dependencyInsight",
266 "--dependency",
267 "com.google.guava:guava",
268 "--configuration",
269 "runtimeClasspath"
270 ],
271 "captureTaskOutput": ":app:dependencyInsight"
272}
273// Reasoning: Using dependencyInsight to isolate the resolution path for a specific artifact.
274```
275
276### Start a dev server and wait for readiness
277
278Tool: `gradle`
279
280```json
281// Step 1: Start the server in the background
282{
283 "commandLine": [":app:bootRun"],
284 "background": true
285}
286// Response: { "buildId": "build_123" }
287
288// Step 2: Wait for readiness signal
289{
290 "buildId": "build_123",
291 "timeout": 60,
292 "waitFor": "Started Application"
293}
294// Reasoning: Background orchestration allows the server to remain active while waiting for readiness.
295```
296
297### Search official Gradle documentation
298
299Tool: `gradle_docs`
300
301```json
302{
303 "query": "tag:dsl signing plugin",
304 "projectRoot": "/absolute/path/to/project"
305}
306// Reasoning: Using the DSL tag to find authoritative syntax for the signing plugin configuration.
307```
308
309### Create a new sub-project module
310
311Tool: `run_shell_command`
312
313```json
314{
315 "command": "New-Item -ItemType Directory -Force -Path subproject/src/main/kotlin"
316}
317// Reasoning: Creating the standard directory structure for a Kotlin JVM project using correct PowerShell syntax.
318```
319
320### List all failed tests in a build
321
322Tool: `query_build`
323
324```json
325{
326 "buildId": "build_abc123",
327 "kind": "TESTS",
328 "outcome": "FAILED"
329}
330// Reasoning: Isolating only the failures from a large test suite for efficient triage.
331```
332
333## Troubleshooting
334
335- **Build Not Found**: If a `BuildId` is not recognized, it may have expired from the recent history cache. Check the dashboard (`query_build()`) for valid active and historical IDs.
336- **Task Output Not Captured**: Ensure the path provided to `captureTaskOutput` matches exactly one of the tasks in the `commandLine`.
337- **Missing environment variables**: Set `invocationArguments: { envSource: "SHELL" }` if Gradle cannot find expected env vars (e.g., `JAVA_HOME`).
338
339## Resources
340
341- [query_build Diagnostics Reference](references/query_build_diagnostics.md) — Complete diagnostic patterns for DASHBOARD, SUMMARY, FAILURES, PROBLEMS, TASKS, TESTS, CONSOLE, and PROGRESS.
342- [Background Monitoring Patterns](references/background_monitoring.md)
343- [Authoritative Diagnostic Tasks](references/diagnostic_tasks.md) — Built-in introspection tasks.
344- [Best Practices Snapshot](references/best_practices.md) — High-level best practices; always verify with `gradle_docs`.
345- [Common Build Patterns](references/common_build_patterns.md) — Idiomatic patterns for multi-project builds, convention plugins, and task registration.
346- [Official Gradle Documentation Research](references/gradle_docs_research.md) — Guidance on using `gradle_docs` for authoritative documentation.