You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 #
Copy file name to clipboardExpand all lines: astro-docs/src/content/docs/technologies/java/gradle/introduction.mdoc
+28-14Lines changed: 28 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ sidebar:
6
6
filter: 'type:References'
7
7
---
8
8
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++.
10
10
11
11
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).
12
12
@@ -18,7 +18,7 @@ Nx adds the following features to your workspace:
18
18
- [Interactively explore your workspace](/docs/features/explore-graph)
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)!
22
22
{% /aside %}
23
23
24
24
## Setup @nx/gradle
@@ -76,7 +76,7 @@ nx build <your gradle library>
76
76
77
77
## How @nx/gradle Infers Tasks
78
78
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:
80
80
81
81
{% tabs syncKey="java-lang" %}
82
82
{% tabitem label="build.gradle.kts" %}
@@ -111,7 +111,7 @@ allprojects {
111
111
{% /tabitem %}
112
112
{% /tabs %}
113
113
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:
115
115
116
116
{% tabs syncKey="os" %}
117
117
{% tabitem label="Mac OS/Linux" %}
@@ -130,11 +130,21 @@ The `dev.nx.gradle.project-graph` plugin introduces a task named `nxProjectGraph
130
130
{% /tabitem %}
131
131
{% /tabs %}
132
132
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 |
| 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
+
133
143
## View Inferred Tasks
134
144
135
145
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.
136
146
137
-
## Setting Up @nx/gradle in a Nx Workspace
147
+
## Setting Up @nx/gradle in an Nx Workspace
138
148
139
149
In any Nx workspace, you can install `@nx/gradle` by running the following command:
140
150
@@ -144,7 +154,7 @@ nx add @nx/gradle
144
154
145
155
## @nx/gradle Configuration
146
156
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`.
148
158
149
159
```json
150
160
// nx.json
@@ -154,21 +164,29 @@ The `@nx/gradle` is configured in the `plugins` array in `nx.json`.
154
164
"plugin": "@nx/gradle",
155
165
"options": {
156
166
"testTargetName": "test",
157
-
"buildTargetName": "build",
158
167
"ciTestTargetName": "test-ci",
168
+
"targetNamePrefix": "gradle-",
159
169
"gradleExecutableDirectory": "./gradle-projects"
160
170
}
161
171
}
162
172
]
163
173
}
164
174
```
165
175
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`.
167
185
168
186
### Custom Gradle Executable Directory
169
187
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.
172
190
173
191
### Batch Mode
174
192
@@ -272,10 +290,6 @@ When you run `nx build-ci <your-gradle-project>`, Nx will:
272
290
273
291
This setup ensures that your build process in CI leverages Nx's caching and distribution capabilities effectively.
274
292
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
-
279
293
### Continuous Tasks
280
294
281
295
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