Skip to content

Commit 8280910

Browse files
authored
docs(gradle): add compat table and target name prefix (#34359)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> A new version compatibility table is added to help users understand which versions of the Gradle plugin work with which versions of the Nx plugin. The targetNamePrefix configuration option is now documented with an explanation of its use case in polyglot workspaces where target name collisions may occur. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
1 parent 37a69f0 commit 8280910

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

astro-docs/src/content/docs/technologies/java/gradle/introduction.mdoc

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebar:
66
filter: 'type:References'
77
---
88

9-
[Gradle](https://gradle.org/) is a fast, dependable, and adaptable open-source build automation tool with an elegant and extensible declarative build language. Gradle supports Android, Java, Kotlin Multiplatform, Groovy, Scala, Javascript, and C/C++.
9+
[Gradle](https://gradle.org/) is a fast, dependable, and adaptable open-source build automation tool with an elegant and extensible declarative build language. Gradle supports Android, Java, Kotlin Multiplatform, Groovy, Scala, JavaScript, and C/C++.
1010

1111
The Nx plugin for Gradle registers Gradle projects in your Nx workspace. It allows Gradle tasks to be run through Nx. Nx effortlessly makes your [CI faster](/docs/guides/nx-cloud/setup-ci).
1212

@@ -18,7 +18,7 @@ Nx adds the following features to your workspace:
1818
- [Interactively explore your workspace](/docs/features/explore-graph)
1919

2020
{% aside type="note" title="Java Compatibility" %}
21-
This plugin requires Java 17 or newer. Using older Java versions is unsupported and may lead to issues. If you need support for an older version, please create an issue on [Github](https://github.com/nrwl/nx)!
21+
This plugin requires Java 17 or newer. Using older Java versions is unsupported and may lead to issues. If you need support for an older version, please create an issue on [GitHub](https://github.com/nrwl/nx)!
2222
{% /aside %}
2323

2424
## Setup @nx/gradle
@@ -76,7 +76,7 @@ nx build <your gradle library>
7676

7777
## How @nx/gradle Infers Tasks
7878

79-
The `@nx/gradle` plugin relies on a companion Gradle plugin, `dev.nx.gradle.project-graph`, to analyze your Gradle build structure. When using `nx add`, the Gradle plugin is added as a dependency to the root Gradle build file. In most cases, the generator will add the task definition to trigger the plugin but if it's missing, add the following configuration to your Gradle configuration:
79+
The `@nx/gradle` plugin relies on a companion Gradle plugin, `dev.nx.gradle.project-graph`, to analyze your Gradle build structure. When using `nx add`, the Gradle plugin is added as a dependency to the root Gradle build file. In most cases, the generator will add the task definition to trigger the plugin, but if it's missing, add the following to your Gradle build file:
8080

8181
{% tabs syncKey="java-lang" %}
8282
{% tabitem label="build.gradle.kts" %}
@@ -111,7 +111,7 @@ allprojects {
111111
{% /tabitem %}
112112
{% /tabs %}
113113

114-
The `dev.nx.gradle.project-graph` plugin introduces a task named `nxProjectGraph`. This task analyzes your Gradle projects and their tasks, outputting the structure as JSON. The `@nx/gradle` plugin then uses this JSON data to accurately build the Nx project graph. If Nx has any issue generate the project graph JSON, you can run the `nxProjectGraph` task manually:
114+
The `dev.nx.gradle.project-graph` plugin introduces a task named `nxProjectGraph`. This task analyzes your Gradle projects and their tasks, outputting the structure as JSON. The `@nx/gradle` plugin then uses this JSON data to accurately build the Nx project graph. If Nx has any issues generating the project graph JSON, you can run the `nxProjectGraph` task manually:
115115

116116
{% tabs syncKey="os" %}
117117
{% tabitem label="Mac OS/Linux" %}
@@ -130,11 +130,21 @@ The `dev.nx.gradle.project-graph` plugin introduces a task named `nxProjectGraph
130130
{% /tabitem %}
131131
{% /tabs %}
132132

133+
## Version Compatibility
134+
135+
The `@nx/gradle` Nx plugin requires a compatible version of the `dev.nx.gradle.project-graph` Gradle plugin. When you run `nx migrate`, the correct version is automatically updated in your Gradle build files. If you need to manually verify or set the version, use the following compatibility table.
136+
137+
| dev.nx.gradle.project-graph version | Minimum required @nx/gradle version | Breaking Change |
138+
| ----------------------------------- | ----------------------------------- | --------------------------------------------------------- |
139+
| 0.1.11 | 22.4+ | Added `includeDependsOn` field to executor options |
140+
| 0.1.10 | 22.2 | Added `nxConfig` field to project node for Nx DSL support |
141+
| 0.1.4 | 21.4 | Added `excludeDependsOn` field to executor options |
142+
133143
## View Inferred Tasks
134144

135145
To view inferred tasks for a project, open the [project details view](/docs/features/explore-graph#explore-projects-in-your-workspace) in Nx Console or run `nx show project my-project` in the command line.
136146

137-
## Setting Up @nx/gradle in a Nx Workspace
147+
## Setting Up @nx/gradle in an Nx Workspace
138148

139149
In any Nx workspace, you can install `@nx/gradle` by running the following command:
140150

@@ -144,7 +154,7 @@ nx add @nx/gradle
144154

145155
## @nx/gradle Configuration
146156

147-
The `@nx/gradle` is configured in the `plugins` array in `nx.json`.
157+
The `@nx/gradle` plugin is configured in the `plugins` array in `nx.json`.
148158

149159
```json
150160
// nx.json
@@ -154,21 +164,29 @@ The `@nx/gradle` is configured in the `plugins` array in `nx.json`.
154164
"plugin": "@nx/gradle",
155165
"options": {
156166
"testTargetName": "test",
157-
"buildTargetName": "build",
158167
"ciTestTargetName": "test-ci",
168+
"targetNamePrefix": "gradle-",
159169
"gradleExecutableDirectory": "./gradle-projects"
160170
}
161171
}
162172
]
163173
}
164174
```
165175

166-
Once a Gradle configuration file has been identified, the targets are created with the name you specify under `testTargetName` or `buildTargetName` in the `nx.json` `plugins` array. The default names for the inferred targets are `test` and `build`.
176+
### Target Name Prefix
177+
178+
In a polyglot workspace supporting projects in different languages, you may have targets with the same name (e.g., `build`, `test`) but different behaviors. By default, Gradle task names are used directly as Nx target names. Use the `targetNamePrefix` option to prefix all Gradle targets with a custom string to distinguish them from other targets in your workspace.
179+
180+
For example, with `"targetNamePrefix": "gradle-"`, Nx will recognize your targets as `gradle-build`, `gradle-test`, `gradle-check`, etc.
181+
182+
### Test Target Name
183+
184+
The `testTargetName` option controls the name of the inferred test target. The default name is `test`.
167185

168186
### Custom Gradle Executable Directory
169187

170-
By default, the @nx/gradle plugin executes the Gradle wrapper found in your project root. If no wrapper exists there, it searches up through parent directories to the workspace root.
171-
To use a Gradle wrapper from a custom location, specify the directory path in your nx.json under the plugins array using the gradleExecutableDirectory option.
188+
By default, the `@nx/gradle` plugin executes the Gradle wrapper found in your project root. If no wrapper exists there, it searches up through parent directories to the workspace root.
189+
To use a Gradle wrapper from a custom location, specify the directory path in your `nx.json` under the plugins array using the `gradleExecutableDirectory` option.
172190

173191
### Batch Mode
174192

@@ -272,10 +290,6 @@ When you run `nx build-ci <your-gradle-project>`, Nx will:
272290

273291
This setup ensures that your build process in CI leverages Nx's caching and distribution capabilities effectively.
274292

275-
##### How to Turn it Off?
276-
277-
To disable the `build-ci` target, simply remove the `ciBuildTargetName` option from the `@nx/gradle` plugin configuration in your `nx.json` file. If `ciTestTargetName` is also removed, then the special CI targets for tests and check will also be turned off.
278-
279293
### Continuous Tasks
280294

281295
Gradle doesn't have a standard way to identify tasks which are [continuous](/docs/reference/project-configuration#continuous), like `bootRun` for serving a Spring Boot project. To ensure Nx handles these continuous tasks correctly, you can explicitly mark them as continuous.

0 commit comments

Comments
 (0)