docs(core): gradle tutorial (#22942)

Create a Gradle tutorial


https://nx-dev-git-fork-isaacplmann-docs-gradle-tutorial-nrwl.vercel.app/getting-started/tutorials/gradle-tutorial

---------

Co-authored-by: FrozenPandaz <jasonjean1993@gmail.com>
This commit is contained in:
Isaac Mann 2024-05-06 14:18:07 -04:00 committed by GitHub
parent 41d21ab9ac
commit 1fe262ad7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 2592 additions and 2 deletions

View File

@ -93,6 +93,14 @@
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Gradle Monorepo",
"path": "/getting-started/tutorials/gradle-tutorial",
"id": "gradle-tutorial",
"isExternal": false,
"children": [],
"disableCollapsible": false
}
],
"disableCollapsible": false
@ -185,6 +193,14 @@
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Gradle Monorepo",
"path": "/getting-started/tutorials/gradle-tutorial",
"id": "gradle-tutorial",
"isExternal": false,
"children": [],
"disableCollapsible": false
}
],
"disableCollapsible": false
@ -237,6 +253,14 @@
"children": [],
"disableCollapsible": false
},
{
"name": "Gradle Monorepo",
"path": "/getting-started/tutorials/gradle-tutorial",
"id": "gradle-tutorial",
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{
"name": "Core Tutorial",
"path": "/core-tutorial",

View File

@ -122,6 +122,17 @@
"isExternal": false,
"path": "/getting-started/tutorials/vue-standalone-tutorial",
"tags": []
},
{
"id": "gradle-tutorial",
"name": "Gradle Monorepo",
"description": "",
"mediaImage": "",
"file": "shared/tutorials/gradle",
"itemList": [],
"isExternal": false,
"path": "/getting-started/tutorials/gradle-tutorial",
"tags": []
}
],
"isExternal": false,
@ -249,6 +260,17 @@
"isExternal": false,
"path": "/getting-started/tutorials/vue-standalone-tutorial",
"tags": []
},
{
"id": "gradle-tutorial",
"name": "Gradle Monorepo",
"description": "",
"mediaImage": "",
"file": "shared/tutorials/gradle",
"itemList": [],
"isExternal": false,
"path": "/getting-started/tutorials/gradle-tutorial",
"tags": []
}
],
"isExternal": false,
@ -321,6 +343,17 @@
"path": "/getting-started/tutorials/vue-standalone-tutorial",
"tags": []
},
"/getting-started/tutorials/gradle-tutorial": {
"id": "gradle-tutorial",
"name": "Gradle Monorepo",
"description": "",
"mediaImage": "",
"file": "shared/tutorials/gradle",
"itemList": [],
"isExternal": false,
"path": "/getting-started/tutorials/gradle-tutorial",
"tags": []
},
"/core-tutorial": {
"id": "core-tutorial",
"name": "Core Tutorial",

View File

@ -69,6 +69,11 @@
"name": "Vue Standalone",
"id": "vue-standalone-tutorial",
"file": "shared/vue-standalone-tutorial/vue-standalone"
},
{
"name": "Gradle Monorepo",
"id": "gradle-tutorial",
"file": "shared/tutorials/gradle"
}
]
}

View File

@ -33,7 +33,7 @@ npx create-nx-workspace@latest
{% /cards %}
{% cards cols="2" lgCols="6" mdCols="3" smCols="2" %}
{% cards cols="2" lgCols="3" mdCols="3" smCols="2" %}
{% link-card title="NPM Workspaces" type="tutorial" url="/getting-started/tutorials/npm-workspaces-tutorial" icon="jsMono" /%}
@ -41,11 +41,17 @@ npx create-nx-workspace@latest
{% link-card title="React Monorepo" type="tutorial" url="/getting-started/tutorials/react-monorepo-tutorial" icon="reactMono" /%}
{% /cards %}
{% cards cols="2" lgCols="4" mdCols="4" smCols="2" %}
{% link-card title="Single Vue App" type="tutorial" url="/getting-started/tutorials/vue-standalone-tutorial" icon="vue" /%}
{% link-card title="Single Angular App" type="tutorial" url="/getting-started/tutorials/angular-standalone-tutorial" icon="angular" /%}
{% link-card title="Angular Monorepo" type="tutorial" url="/getting-started/tutorials/angular-monorepo-tutorial" icon="angularMono" /%}
{% link-card title="Single Vue App" type="tutorial" url="/getting-started/tutorials/vue-standalone-tutorial" icon="vue" /%}
{% link-card title="Gradle Monorepo" type="tutorial" url="/getting-started/tutorials/gradle-tutorial" icon="gradle" /%}
{% /cards %}

View File

@ -12,6 +12,7 @@
- [Angular Standalone](/getting-started/tutorials/angular-standalone-tutorial)
- [Angular Monorepo](/getting-started/tutorials/angular-monorepo-tutorial)
- [Vue Standalone](/getting-started/tutorials/vue-standalone-tutorial)
- [Gradle Monorepo](/getting-started/tutorials/gradle-tutorial)
- [Core Tutorial](/core-tutorial)
- [1 - Create Blog](/core-tutorial/01-create-blog)
- [2 - Create CLI](/core-tutorial/02-create-cli)

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,949 @@
{
"hash": "ad0ea8f7ae85c873d6478c31b51a95c54115a49844d62a5b3972232ac82137d0",
"projects": [
{
"name": "application",
"type": "lib",
"data": {
"root": "application",
"name": "application",
"metadata": {
"technologies": ["gradle"]
},
"targets": {
"bootRun": {
"options": {
"cwd": "application",
"command": "../gradlew bootRun"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"bootTestRun": {
"options": {
"cwd": "application",
"command": "../gradlew bootTestRun"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"assemble": {
"options": {
"cwd": "application",
"command": "../gradlew assemble"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"bootBuildImage": {
"options": {
"cwd": "application",
"command": "../gradlew bootBuildImage"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"bootJar": {
"options": {
"cwd": "application",
"command": "../gradlew bootJar"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"build": {
"options": {
"cwd": "application",
"command": "../gradlew build"
},
"cache": true,
"inputs": ["production", "^production"],
"outputs": ["{workspaceRoot}/application/build"],
"dependsOn": ["^build", "classes"],
"executor": "nx:run-commands",
"configurations": {}
},
"buildDependents": {
"options": {
"cwd": "application",
"command": "../gradlew buildDependents"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"buildNeeded": {
"options": {
"cwd": "application",
"command": "../gradlew buildNeeded"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"classes": {
"options": {
"cwd": "application",
"command": "../gradlew classes"
},
"cache": true,
"inputs": ["default", "^default"],
"outputs": ["{workspaceRoot}/application/build/classes"],
"dependsOn": ["^classes"],
"executor": "nx:run-commands",
"configurations": {}
},
"clean": {
"options": {
"cwd": "application",
"command": "../gradlew clean"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"jar": {
"options": {
"cwd": "application",
"command": "../gradlew jar"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"resolveMainClassName": {
"options": {
"cwd": "application",
"command": "../gradlew resolveMainClassName"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"resolveTestMainClassName": {
"options": {
"cwd": "application",
"command": "../gradlew resolveTestMainClassName"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"testClasses": {
"options": {
"cwd": "application",
"command": "../gradlew testClasses"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"javadoc": {
"options": {
"cwd": "application",
"command": "../gradlew javadoc"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"buildEnvironment": {
"options": {
"cwd": "application",
"command": "../gradlew buildEnvironment"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"dependencies": {
"options": {
"cwd": "application",
"command": "../gradlew dependencies"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"dependencyInsight": {
"options": {
"cwd": "application",
"command": "../gradlew dependencyInsight"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"dependencyManagement": {
"options": {
"cwd": "application",
"command": "../gradlew dependencyManagement"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"help": {
"options": {
"cwd": "application",
"command": "../gradlew help"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"javaToolchains": {
"options": {
"cwd": "application",
"command": "../gradlew javaToolchains"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"outgoingVariants": {
"options": {
"cwd": "application",
"command": "../gradlew outgoingVariants"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"projects": {
"options": {
"cwd": "application",
"command": "../gradlew projects"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"properties": {
"options": {
"cwd": "application",
"command": "../gradlew properties"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"resolvableConfigurations": {
"options": {
"cwd": "application",
"command": "../gradlew resolvableConfigurations"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"tasks": {
"options": {
"cwd": "application",
"command": "../gradlew tasks"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"projectReport": {
"options": {
"cwd": "application",
"command": "../gradlew projectReport"
},
"cache": false,
"outputs": ["{workspaceRoot}/application/build/reports/project"],
"executor": "nx:run-commands",
"configurations": {}
},
"check": {
"options": {
"cwd": "application",
"command": "../gradlew check"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"test": {
"options": {
"cwd": "application",
"command": "../gradlew test"
},
"cache": true,
"inputs": ["default", "^production"],
"dependsOn": ["classes"],
"executor": "nx:run-commands",
"configurations": {}
}
},
"implicitDependencies": [],
"tags": []
}
},
{
"name": "library",
"type": "lib",
"data": {
"root": "library",
"name": "library",
"metadata": {
"technologies": ["gradle"]
},
"targets": {
"assemble": {
"options": {
"cwd": "library",
"command": "../gradlew assemble"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"build": {
"options": {
"cwd": "library",
"command": "../gradlew build"
},
"cache": true,
"inputs": ["production", "^production"],
"outputs": ["{workspaceRoot}/library/build"],
"dependsOn": ["^build", "classes"],
"executor": "nx:run-commands",
"configurations": {}
},
"buildDependents": {
"options": {
"cwd": "library",
"command": "../gradlew buildDependents"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"buildNeeded": {
"options": {
"cwd": "library",
"command": "../gradlew buildNeeded"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"classes": {
"options": {
"cwd": "library",
"command": "../gradlew classes"
},
"cache": true,
"inputs": ["default", "^default"],
"outputs": ["{workspaceRoot}/library/build/classes"],
"dependsOn": ["^classes"],
"executor": "nx:run-commands",
"configurations": {}
},
"clean": {
"options": {
"cwd": "library",
"command": "../gradlew clean"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"jar": {
"options": {
"cwd": "library",
"command": "../gradlew jar"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"testClasses": {
"options": {
"cwd": "library",
"command": "../gradlew testClasses"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"javadoc": {
"options": {
"cwd": "library",
"command": "../gradlew javadoc"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"buildEnvironment": {
"options": {
"cwd": "library",
"command": "../gradlew buildEnvironment"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"dependencies": {
"options": {
"cwd": "library",
"command": "../gradlew dependencies"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"dependencyInsight": {
"options": {
"cwd": "library",
"command": "../gradlew dependencyInsight"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"dependencyManagement": {
"options": {
"cwd": "library",
"command": "../gradlew dependencyManagement"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"help": {
"options": {
"cwd": "library",
"command": "../gradlew help"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"javaToolchains": {
"options": {
"cwd": "library",
"command": "../gradlew javaToolchains"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"outgoingVariants": {
"options": {
"cwd": "library",
"command": "../gradlew outgoingVariants"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"projects": {
"options": {
"cwd": "library",
"command": "../gradlew projects"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"properties": {
"options": {
"cwd": "library",
"command": "../gradlew properties"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"resolvableConfigurations": {
"options": {
"cwd": "library",
"command": "../gradlew resolvableConfigurations"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"tasks": {
"options": {
"cwd": "library",
"command": "../gradlew tasks"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"projectReport": {
"options": {
"cwd": "library",
"command": "../gradlew projectReport"
},
"cache": false,
"outputs": ["{workspaceRoot}/library/build/reports/project"],
"executor": "nx:run-commands",
"configurations": {}
},
"check": {
"options": {
"cwd": "library",
"command": "../gradlew check"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"test": {
"options": {
"cwd": "library",
"command": "../gradlew test"
},
"cache": true,
"inputs": ["default", "^production"],
"dependsOn": ["classes"],
"executor": "nx:run-commands",
"configurations": {}
}
},
"implicitDependencies": [],
"tags": []
}
},
{
"name": "gradle-tutorial",
"type": "lib",
"data": {
"root": ".",
"name": "gradle-tutorial",
"metadata": {
"technologies": ["gradle"]
},
"targets": {
"bootRun": {
"options": {
"cwd": ".",
"command": "gradlew bootRun"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"bootTestRun": {
"options": {
"cwd": ".",
"command": "gradlew bootTestRun"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"assemble": {
"options": {
"cwd": ".",
"command": "gradlew assemble"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"bootBuildImage": {
"options": {
"cwd": ".",
"command": "gradlew bootBuildImage"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"bootJar": {
"options": {
"cwd": ".",
"command": "gradlew bootJar"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"build": {
"options": {
"cwd": ".",
"command": "gradlew build"
},
"cache": true,
"inputs": ["production", "^production"],
"outputs": ["{workspaceRoot}/build"],
"dependsOn": ["^build", "classes"],
"executor": "nx:run-commands",
"configurations": {}
},
"buildDependents": {
"options": {
"cwd": ".",
"command": "gradlew buildDependents"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"buildNeeded": {
"options": {
"cwd": ".",
"command": "gradlew buildNeeded"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"classes": {
"options": {
"cwd": ".",
"command": "gradlew classes"
},
"cache": true,
"inputs": ["default", "^default"],
"outputs": ["{workspaceRoot}/build/classes"],
"dependsOn": ["^classes"],
"executor": "nx:run-commands",
"configurations": {}
},
"clean": {
"options": {
"cwd": ".",
"command": "gradlew clean"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"jar": {
"options": {
"cwd": ".",
"command": "gradlew jar"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"resolveMainClassName": {
"options": {
"cwd": ".",
"command": "gradlew resolveMainClassName"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"resolveTestMainClassName": {
"options": {
"cwd": ".",
"command": "gradlew resolveTestMainClassName"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"testClasses": {
"options": {
"cwd": ".",
"command": "gradlew testClasses"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"init": {
"options": {
"cwd": ".",
"command": "gradlew init"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"wrapper": {
"options": {
"cwd": ".",
"command": "gradlew wrapper"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"javadoc": {
"options": {
"cwd": ".",
"command": "gradlew javadoc"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"buildEnvironment": {
"options": {
"cwd": ".",
"command": "gradlew buildEnvironment"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"dependencies": {
"options": {
"cwd": ".",
"command": "gradlew dependencies"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"dependencyInsight": {
"options": {
"cwd": ".",
"command": "gradlew dependencyInsight"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"dependencyManagement": {
"options": {
"cwd": ".",
"command": "gradlew dependencyManagement"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"help": {
"options": {
"cwd": ".",
"command": "gradlew help"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"javaToolchains": {
"options": {
"cwd": ".",
"command": "gradlew javaToolchains"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"outgoingVariants": {
"options": {
"cwd": ".",
"command": "gradlew outgoingVariants"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"projects": {
"options": {
"cwd": ".",
"command": "gradlew projects"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"properties": {
"options": {
"cwd": ".",
"command": "gradlew properties"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"resolvableConfigurations": {
"options": {
"cwd": ".",
"command": "gradlew resolvableConfigurations"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"tasks": {
"options": {
"cwd": ".",
"command": "gradlew tasks"
},
"cache": false,
"executor": "nx:run-commands",
"configurations": {}
},
"projectReport": {
"options": {
"cwd": ".",
"command": "gradlew projectReport"
},
"cache": false,
"outputs": ["{workspaceRoot}/build/reports/project"],
"executor": "nx:run-commands",
"configurations": {}
},
"check": {
"options": {
"cwd": ".",
"command": "gradlew check"
},
"cache": true,
"executor": "nx:run-commands",
"configurations": {}
},
"test": {
"options": {
"cwd": ".",
"command": "gradlew test"
},
"cache": true,
"inputs": ["default", "^production"],
"dependsOn": ["classes"],
"executor": "nx:run-commands",
"configurations": {}
}
},
"implicitDependencies": [],
"tags": []
}
}
],
"dependencies": {
"application": [
{
"source": "application",
"target": "library",
"type": "static"
}
],
"library": [],
"gradle-tutorial": []
},
"fileMap": {
"gradle-tutorial": [
{
"file": ".gitignore",
"hash": "14909406639319951657"
},
{
"file": ".mvn/wrapper/maven-wrapper.jar",
"hash": "4599048718252132452"
},
{
"file": ".mvn/wrapper/maven-wrapper.properties",
"hash": "14062264138023377782"
},
{
"file": ".nx/nxw.js",
"hash": "11254603345854076312"
},
{
"file": "README.md",
"hash": "2143394647937164316"
},
{
"file": "build.gradle",
"hash": "6776876968973565169"
},
{
"file": "gradle/wrapper/gradle-wrapper.jar",
"hash": "4964452923295747250"
},
{
"file": "gradle/wrapper/gradle-wrapper.properties",
"hash": "6992607940248896982"
},
{
"file": "gradlew",
"hash": "6979324130797723579"
},
{
"file": "gradlew.bat",
"hash": "8837338129170646035"
},
{
"file": "nx",
"hash": "17165975525224888679"
},
{
"file": "nx.bat",
"hash": "16828809655253213278"
},
{
"file": "nx.json",
"hash": "16332841804597347663"
},
{
"file": "settings.gradle",
"hash": "5690477904066095133"
}
],
"application": [
{
"file": "application/build.gradle",
"hash": "13223387111008998466",
"deps": ["library"]
},
{
"file": "application/settings.gradle",
"hash": "18286272227920383284"
},
{
"file": "application/src/main/java/com/example/multimodule/application/DemoApplication.java",
"hash": "117361831080317523"
},
{
"file": "application/src/main/resources/application.properties",
"hash": "18341909134911292471"
},
{
"file": "application/src/test/java/com/example/multimodule/application/DemoApplicationTest.java",
"hash": "12794301020412404095"
}
],
"library": [
{
"file": "library/build.gradle",
"hash": "10874096726061397019"
},
{
"file": "library/settings.gradle",
"hash": "13735992102452590570"
},
{
"file": "library/src/main/java/com/example/multimodule/service/MyService.java",
"hash": "1785389597461451392"
},
{
"file": "library/src/main/java/com/example/multimodule/service/ServiceProperties.java",
"hash": "5222601539204689670"
},
{
"file": "library/src/test/java/com/example/multimodule/service/MyServiceTest.java",
"hash": "7173828893536126792"
}
]
},
"workspaceLayout": {
"appsDir": "apps",
"libsDir": "libs"
},
"affectedProjectIds": [],
"focus": null,
"groupByFolder": false,
"exclude": [],
"isPartial": false
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 KiB

View File

@ -0,0 +1,343 @@
---
title: 'Gradle Tutorial'
description: In this tutorial you'll add Nx to an existing Gradle repo
---
# Gradle Tutorial
In this tutorial, you'll learn how to add Nx to a repository with an existing Gradle setup. You'll see how Nx can
provide immediate value.
## Prerequisites
Make sure that you have [Gradle](https://gradle.org/) installed on your system.
Consult [Gradle's installation guide](https://docs.gradle.org/current/userguide/installation.html) for instruction that
are specific to your operating system.
To verify that Gradle was installed correctly, run this command:
```shell
gradle --version
```
Nx also requires NodeJS to be installed. If you do not have NodeJS installed, you can
install it from the [NodeJS website](https://nodejs.org/en/download).
```shell
node -v
```
## Getting Started
This tutorial picks up where [Spring framework](https://spring.io/)'s guide for [Multi-Module Projects](https://spring.io/guides/gs/multi-module) leaves off.
Fork [the sample repository](https://github.com/nrwl/gradle-tutorial):
[https://github.com/nrwl/gradle-tutorial](https://github.com/nrwl/gradle-tutorial)
And then clone it on your local machine:
```shell
git clone https://github.com/<your-username>/gradle-tutorial.git
```
The Multi-Module Spring Tutorial left us with 2 projects:
- The main `application` project which contains the Spring `DemoApplication`
- A `library` project which contains a Service used in the `DemoApplication`
You can see the above 2 projects by running `./gradlew projects`
```text {% command="./gradlew projects" %}
> Task :projects
------------------------------------------------------------
Root project 'gradle-tutorial'
------------------------------------------------------------
Root project 'gradle-tutorial'
+--- Project ':application'
\--- Project ':library'
```
## Add Nx
Nx is a build system with built in tooling and advanced CI capabilities. It helps you maintain and scale monorepos,
both locally and on CI. We will explore the features of Nx in this tutorial by adding it to the Gradle workspace above.
To add Nx, run `npx nx@latest init`.
This command will download the latest version of Nx and help set up your repository to take advantage of it. Nx will
also detect Gradle is used in the repo so it will propose adding the `@nx/gradle` plugin to integrate Gradle with Nx.
Select the plugin and continue with the setup.
Similar to Gradle, Nx can be run with the `nx` or `nx.bat` executables. We will learn about some of the Nx commands in
the following sections.
## Explore Your Workspace
Like Gradle, Nx understands your workspace as a graph of projects. Nx uses this graph for many things which we will
learn about in following sections. To visualize this graph in your browser, Run the following command and click the
"Show all projects" button in the left sidebar.
You will recognize that the projects which are shown, are the same projects which Gradle shows.
The `@nx/gradle` plugin reflects the graph of projects in Gradle into the Nx Project Graph. As projects
are created, deleted, and change their dependencies, Nx will automatically recalculate the graph. Exploring this graph
visually is vital to understanding how your code is structured and how Nx and Gradle behaves.
{% tabs %}
{% tab label="Mac/Linux" %}
```shell
./nx graph
```
{% /tab %}
{% tab label="Windows" %}
```shell
./nx.bat graph
```
{% /tab %}
{% /tabs %}
{% graph title="Gradle Projects" height="200px" jsonFile="shared/tutorials/gradle-project-graph.json" %}
{% /graph %}
## Running Tasks
Nx is a task runner built for monorepos. It can run a single task for a single project, a task for all projects, and
even intelligently run a subset of tasks based on the changes you've made in your repository. Nx also has sophisticated
computation caching to reuse the results of tasks. We will explore how Nx adds to the task running Gradle provides.
Before we start running tasks, let's explore the tasks available for the `application` project. The `@nx/gradle` plugin
that we've installed reflects Gradle's tasks to Nx, which allows it to run any of the Gradle tasks defined for that project. You can view the available tasks either through [Nx Console](/getting-started/editor-setup) or from the terminal:
```shell {% path="~/gradle-tutorial" %}
./nx show project application --web
```
{% project-details title="Project Details View" jsonFile="shared/tutorials/gradle-pdv.json" %}
{% /project-details %}
The Nx command to run the `build` task for the `application` project is:
```shell
./nx run application:build
```
When Nx runs a Gradle task, it hands off the execution of that task to Gradle, so all task dependencies and
configuration settings in the Gradle configuration are still respected.
By running the task via Nx, however, the task computation was cached for reuse. Now, running `./nx run application:build`
again, will complete almost instantly as the result from the previous execution will be used.
```{% command="./nx run application:build" %}
✔ 1/1 dependent project tasks succeeded [1 read from cache]
Hint: you can run the command with --verbose to see the full dependent project outputs
—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
> nx run application:classes [existing outputs match the cache, left as is]
> ./gradlew :application:classes
> Task :library:compileJava UP-TO-DATE
> Task :library:processResources NO-SOURCE
> Task :library:classes UP-TO-DATE
> Task :library:jar UP-TO-DATE
> Task :application:compileJava UP-TO-DATE
> Task :application:processResources UP-TO-DATE
> Task :application:classes UP-TO-DATE
BUILD SUCCESSFUL in 647ms
4 actionable tasks: 4 up-to-date
> nx run application:build [existing outputs match the cache, left as is]
> ./gradlew :application:build
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.5/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD SUCCESSFUL in 768ms
9 actionable tasks: 1 executed, 8 up-to-date
—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
NX Successfully ran target build for project application and 3 tasks it depends on (30ms)
Nx read the output from the cache instead of running the command for 4 out of 4 tasks.
```
Now that we've run one task, let's run all the `build` tasks in the repository with the Nx `run-many` command. This is similar to Gradle's `./gradlew build` command.
```{% command="./nx run-many -t build" %}
✔ nx run library:classes [existing outputs match the cache, left as is]
✔ nx run library:build [existing outputs match the cache, left as is]
✔ nx run application:classes [existing outputs match the cache, left as is]
✔ nx run application:build [existing outputs match the cache, left as is]
✔ nx run gradle-tutorial:classes (1s)
✔ nx run gradle-tutorial:build (1s)
—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
NX Successfully ran target build for 3 projects and 3 tasks they depend on (2s)
Nx read the output from the cache instead of running the command for 4 out of 6 tasks.
```
Again, because Nx cached the tasks when the application was built, most of the tasks here were near instant. The only
ones which needed to be done is the root project's build. Running the command one more time, will be near instant as
then all the tasks will be restored from the cache.
## Run Tasks for Affected Projects
Nx doesn't just cache your task results, it can also [eliminate the need to run unnecessary tasks](/ci/features/affected).
First, commit any outstanding changes to the `main` branch locally:
```shell
git commit -am "changes"
```
Next make a small change to the `application` code:
```java {% fileName="application/src/main/java/com/example/multimodule/application/DemoApplication.java" highlightLines=[21] %}
package com.example.multimodule.application;
import com.example.multimodule.service.MyService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication(scanBasePackages = "com.example.multimodule")
@RestController
public class DemoApplication {
private final MyService myService;
public DemoApplication(MyService myService) {
this.myService = myService;
}
@GetMapping("/")
public String home() {
return myService.message() + " changed!";
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
```
As a developer, we know that this change only affects the `application` project, not the `library` project. We would
run `./nx run application:test` to verify our changes. In CI, teams often run all test tasks rerunning
the `library:test` task unnecessarily.
For a repository with only a few projects, you can manually calculate which projects are affected. As the repository grows, it becomes critical to have a tool like Nx that understands the project dependency graph and eliminates wasted time in CI.
The `./nx affected` command solves this problem. Nx uses its project graph in conjunction with git history to only run
tasks for projects that may have been affected by the changes that you made.
To run the `test` tasks for projects affected by this change, run:
```shell
./nx affected -t test
```
Notice that this command does not run the `test` task for the `library` project, since it could not have been affected by the code change.
## Set Up CI for Your Gradle Workspace
This tutorial walked you through how Nx can improve the local development experience, but the biggest difference Nx makes is in CI. As repositories get bigger, making sure that the CI is fast, reliable and maintainable can get very challenging. Nx provides a solution.
- Nx reduces wasted time in CI with the [`affected` command](/ci/features/affected).
- Nx Replay's [remote caching](/ci/features/remote-cache) will reuse task artifacts from different CI executions making sure you will never run the same computation twice.
- Nx Agents [efficiently distribute tasks across machines](/ci/concepts/parallelization-distribution) ensuring constant CI time regardless of the repository size. The right number of machines is allocated for each PR to ensure good performance without wasting compute.
- Nx Atomizer [automatically splits](/ci/features/split-e2e-tasks) large e2e tests to distribute them across machines. Nx can also automatically [identify and rerun flaky e2e tests](/ci/features/flaky-tasks).
### Generating a CI Workflow
If you are starting a new project, you can use the following command to generate a CI workflow file.
```shell
./nx generate @nx/gradle:ci-workflow --ci=github
```
This generator creates a `.github/workflows/ci.yml` file that contains a CI pipeline that will run the `test` and `build` tasks for projects that are affected by any given PR.
The key line in the CI pipeline is:
```
./nx affected -t test build
```
### Connecting to Nx Cloud
Nx Cloud is a companion app for your CI system that provides remote caching, task distribution, e2e tests deflaking, better DX and more.
To connect to Nx Cloud:
- Commit and push your changes to GitHub
- Go to [https://cloud.nx.app](https://cloud.nx.app), create an account, and connect your repository
![Connect to your repository](/shared/tutorials/connect-to-repository.png)
`cloud.nx.app` will send a PR to your repository enabling Nx Cloud, after which caching, distribution and more will start working.
![Add an Nx Cloud access token to your repository dialog](/shared/tutorials/send-cloud-pr.png)
Once you merge that PR, you'll be able to see CI pipeline runs appearing in the Nx Cloud dashboard:
![CI Pipeline Executiosn](/shared/tutorials/ci-pipeline-executions.png)
### Enable a Distributed CI Pipeline
The current CI pipeline runs on a single machine and can only handle small workspaces. To transform your CI into a CI that runs on multiple machines and can handle workspaces of any size, uncomment the `npx nx-cloud start-ci-run` line in the `.github/workflows/ci.yml` file.
```yml
# Connect your workspace on nx.app and uncomment this to enable task distribution.
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested
- run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build"
```
![Gradle run details](/shared/tutorials/gradle-run-details.png)
For more information about how Nx can improve your CI pipeline, check out one of these detailed tutorials:
- [Circle CI with Nx](/ci/intro/tutorials/circle)
- [GitHub Actions with Nx](/ci/intro/tutorials/github-actions)
## Summary
Now that you have added Nx to this sample Gradle repository, you have learned several ways that Nx can help your
organization:
- Nx reflects the Gradle graph into the Nx graph
- Nx's dependency graph visualisation helps you understand your codebase
- Nx caches task results and reuses them when the same task is rerun later
- Nx intelligently determines which tasks are `affected` by code changes to reduce waste in CI
- Nx Cloud provides remote caching and distributed task execution to speed up CI
## Next Steps
Connect with the rest of the Nx community with these resources:
- [Join the Official Nx Discord Server](https://go.nx.dev/community) to ask questions and find out the latest news about
Nx.
- [Follow Nx on Twitter](https://twitter.com/nxdevtools) to stay up to date with Nx news
- [Read our Nx blog](https://blog.nrwl.io/)
- [Subscribe to our Youtube channel](https://www.youtube.com/@nxdevtools) for demos and Nx insights

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB