Gradle 安装与 CLI
安装 Gradle,了解其命令行界面,并执行基本构建命令。
Gradle 安装与 CLI 是 CoddyKit 上的免费 Groovy & Gradle: JVM Automation and Build Engineering 课时。 这是第 1 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Groovy & Gradle: JVM Automation and Build Engineering 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Groovy & Gradle: JVM Automation and Build Engineering 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Meet the Gradle CLI
The Gradle Command Line Interface (CLI) is your main tool for interacting with Gradle. It's how you tell Gradle what to do, like building your project or running tests.
Understanding the CLI is crucial for automating your build processes and managing your projects effectively.
Java is Required!
Before installing Gradle, you need to have the Java Development Kit (JDK) installed on your system. Gradle runs on the Java Virtual Machine (JVM), just like Java applications.
- Ensure you have JDK 8 or higher.
- You can check your Java version with:
java -version
How to Install Gradle
There are several ways to install Gradle. For beginners, using a version manager like SDKMAN! is highly recommended. It simplifies managing multiple SDK versions.
- SDKMAN!: Easy and flexible.
- Manual Download: More setup required.
- Package Managers: Homebrew (macOS), Chocolatey (Windows).
Install Gradle via SDKMAN!
SDKMAN! (Software Development Kit Manager) makes installing Gradle super easy. If you don't have SDKMAN!, install it first by following instructions on sdkman.io.
Once SDKMAN! is ready, open your terminal and run:
sdk install gradleCheck Your Gradle Version
After installation, it's a good practice to verify that Gradle is correctly installed and accessible from your terminal. This command shows the Gradle version and other environment details.
Run this in your terminal:
gradle -vDiscovering Gradle Tasks
The most common command to start with is gradle tasks. This command lists all available tasks for the current project. If you're not in a Gradle project, it shows generic tasks.
Let's try it:
gradle tasksWhat `gradle tasks` Shows
When you run gradle tasks, you'll see categories like "Build tasks", "Verification tasks", etc., each with a list of tasks and their descriptions.
- Tasks: Are the actual actions Gradle performs (e.g.,
build,clean,test). - Description: Explains what each task does.
This output helps you understand what operations your project supports.
Need Help? Use `gradle help`
Gradle has a built-in help system. If you want to know more about a specific task, you can use the help task with the --task option.
For example, to learn about the build task:
gradle help --task buildIntro to Gradle Wrapper (gradlew)
Many Gradle projects include a Gradle Wrapper (gradlew or gradlew.bat). This script ensures everyone uses the same Gradle version for a project, even if they don't have Gradle installed globally.
You'll often run commands like ./gradlew build instead of gradle build.
Test Your CLI Knowledge
Let's check your understanding of basic Gradle commands!
Recap: Gradle CLI Essentials
Great job! In this lesson, you learned how to:
- Understand the role of the Gradle CLI.
- Install Gradle using SDKMAN!.
- Verify your installation with
gradle -v. - List available tasks using
gradle tasks. - Get help for specific tasks with
gradle help --task <taskName>. - Briefly grasp the concept of the Gradle Wrapper.
Next, we'll dive into setting up a basic Gradle project!
常见问题解答
「Gradle 安装与 CLI」课时是免费的吗?
是的 — 「Gradle 安装与 CLI」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Groovy & Gradle: JVM Automation and Build Engineering 课程的其余内容,请升级到 CoddyKit PRO。 Groovy & Gradle: JVM Automation and Build Engineering 课程共包含 4 节课。
「Gradle 安装与 CLI」这节课中我会学到什么?
安装 Gradle,了解其命令行界面,并执行基本构建命令。 你通过在浏览器中直接运行的动手代码来练习 Groovy & Gradle: JVM Automation and Build Engineering,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Groovy & Gradle: JVM Automation and Build Engineering 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Groovy & Gradle: JVM Automation and Build Engineering 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 1 节课,共 4 节。
「Gradle 安装与 CLI」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Groovy & Gradle: JVM Automation and Build Engineering 课中编写并运行代码吗?
能。每节 Groovy & Gradle: JVM Automation and Build Engineering 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- Gradle 安装与 CLI
- Gradle 项目结构
- 任务与构建生命周期
- 多项目构建与 settings 文件