前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Gradle 命令行介紹和安裝教程

Gradle 命令行介紹和安裝教程

作者头像
一个会写诗的程序员
发布2020-09-10 10:22:40
9950
发布2020-09-10 10:22:40
举报

Gradle 命令行

代码语言:javascript
复制
$ gradle -h

USAGE: gradle [option...] [task...]

-?, -h, --help                     Shows this help message.
-a, --no-rebuild                   Do not rebuild project dependencies.
-b, --build-file                   Specify the build file.
--build-cache                      Enables the Gradle build cache. Gradle will try to reuse outputs from previous builds.
-c, --settings-file                Specify the settings file.
--configuration-cache              Enables the configuration cache. Gradle will try to reuse the build configuration from previous builds. [incubating]
--configuration-cache-problems     Configures how the configuration cache handles problems (fail or warn). Defaults to fail. [incubating]
--configure-on-demand              Configure necessary projects only. Gradle will attempt to reduce configuration time for large multi-project builds. [incubating]
--console                          Specifies which type of console output to generate. Values are 'plain', 'auto' (default), 'rich' or 'verbose'.
--continue                         Continue task execution after a task failure.
-D, --system-prop                  Set system property of the JVM (e.g. -Dmyprop=myvalue).
-d, --debug                        Log in debug mode (includes normal stacktrace).
--daemon                           Uses the Gradle Daemon to run the build. Starts the Daemon if not running.
--export-keys                      Exports the public keys used for dependency verification. [incubating]
-F, --dependency-verification      Configures the dependency verification mode (strict, lenient or off) [incubating]
--foreground                       Starts the Gradle Daemon in the foreground.
-g, --gradle-user-home             Specifies the gradle user home directory.
-I, --init-script                  Specify an initialization script.
-i, --info                         Set log level to info.
--include-build                    Include the specified build in the composite.
-M, --write-verification-metadata  Generates checksums for dependencies used in the project (comma-separated list) [incubating]
-m, --dry-run                      Run the builds with all task actions disabled.
--max-workers                      Configure the number of concurrent workers Gradle is allowed to use.
--no-build-cache                   Disables the Gradle build cache.
--no-configuration-cache           Disables the configuration cache. [incubating]
--no-configure-on-demand           Disables the use of configuration on demand. [incubating]
--no-daemon                        Do not use the Gradle daemon to run the build. Useful occasionally if you have configured Gradle to always run with the daemon by default.
--no-parallel                      Disables parallel execution to build projects.
--no-scan                          Disables the creation of a build scan. For more information about build scans, please visit https://gradle.com/build-scans.
--no-watch-fs                      Disables watching the file system. [incubating]
--offline                          Execute the build without accessing network resources.
-P, --project-prop                 Set project property for the build script (e.g. -Pmyprop=myvalue).
-p, --project-dir                  Specifies the start directory for Gradle. Defaults to current directory.
--parallel                         Build projects in parallel. Gradle will attempt to determine the optimal number of executor threads to use.
--priority                         Specifies the scheduling priority for the Gradle daemon and all processes launched by it. Values are 'normal' (default) or 'low' [incubating]
--profile                          Profile build execution time and generates a report in the <build_dir>/reports/profile directory.
--project-cache-dir                Specify the project-specific cache directory. Defaults to .gradle in the root project directory.
-q, --quiet                        Log errors only.
--refresh-dependencies             Refresh the state of dependencies.
--refresh-keys                     Refresh the public keys used for dependency verification. [incubating]
--rerun-tasks                      Ignore previously cached task results.
-S, --full-stacktrace              Print out the full (very verbose) stacktrace for all exceptions.
-s, --stacktrace                   Print out the stacktrace for all exceptions.
--scan                             Creates a build scan. Gradle will emit a warning if the build scan plugin has not been applied. (https://gradle.com/build-scans)
--status                           Shows status of running and recently stopped Gradle Daemon(s).
--stop                             Stops the Gradle Daemon if it is running.
-t, --continuous                   Enables continuous build. Gradle does not exit and will re-execute tasks when task file inputs change.
--update-locks                     Perform a partial update of the dependency lock, letting passed in module notations change version. [incubating]
-v, --version                      Print version info.
-w, --warn                         Set log level to warn.
--warning-mode                     Specifies which mode of warnings to generate. Values are 'all', 'fail', 'summary'(default) or 'none'
--watch-fs                         Enables watching the file system for changes, allowing data about the file system to be re-used for the next build. [incubating]
--write-locks                      Persists dependency resolution for locked configurations, ignoring existing locking information if it exists [incubating]
-x, --exclude-task                 Specify a task to be excluded from execution.

直接gradle

代码语言:javascript
复制
$ gradle
=======================================
Elasticsearch Build Hamster says Hello!
  Gradle Version        : 6.6.1
  OS Info               : Mac OS X 10.14.5 (x86_64)
  JDK Version           : 11 (Oracle JDK)
  JAVA_HOME             : /Library/Java/JavaVirtualMachines/jdk-11.0.8.jdk/Contents/Home
  Random Testing Seed   : 81391CAF341C3379
  In FIPS 140 mode      : false
=======================================

> Task :help

Welcome to Gradle 6.6.1.

To run a build, run gradle <task> ...

To see a list of available tasks, run gradle tasks

To see a list of command-line options, run gradle --help

To see more detail about a task, run gradle help --task <task>

For troubleshooting, visit https://help.gradle.org

BUILD SUCCESSFUL in 4s
1 actionable task: 1 executed

gradle build

装配所有输出并运行所有检查

gradle run

运行所有任务

gradle check

验证任务,包括测试和初始化

gradle clean

清理所有输出

gradle projects

项目报告,包括子项目

gradle tasks

所有的tasks列表

gradle -q help –task xxx

展示指定任务的详细信息

gradle buildEnvironment

展示构建环境依赖关系报告

gradle dependencyInsight

展示依赖关系报告

gradle model

展示模型关系报告

gradle dependencies

展示項目依賴。

代码语言:javascript
复制
$ gradle dependencies
<-------------> 0% INITIALIZING [47s]
=======================================
Elasticsearch Build Hamster says Hello!
  Gradle Version        : 6.6.1
  OS Info               : Mac OS X 10.14.5 (x86_64)
  JDK Version           : 11 (Oracle JDK)
  JAVA_HOME             : /Library/Java/JavaVirtualMachines/jdk-11.0.8.jdk/Contents/Home
  Random Testing Seed   : 4F74E0BEC4127C06
  In FIPS 140 mode      : false
=======================================

> Task :dependencies

------------------------------------------------------------
Root project - Elasticsearch subproject :
------------------------------------------------------------

elasticsearch_7.0.0_archive_darwin_default
\--- elasticsearch-distribution:elasticsearch:7.0.0

elasticsearch_7.0.0_archive_darwin_oss
\--- elasticsearch-distribution:elasticsearch-oss:7.0.0

elasticsearch_7.0.1_archive_darwin_default
\--- elasticsearch-distribution:elasticsearch:7.0.1
。。。
es_distro_file_local
\--- project :distribution:archives:darwin-tar

es_distro_file_testclusters--runTask-0-8.0.0-SNAPSHOT-
\--- project :distribution:archives:darwin-tar

。。。

(*) - dependencies omitted (listed previously)

A web-based, searchable dependency report is available by adding the --scan option.

BUILD SUCCESSFUL in 5m 13s
1 actionable task: 1 executed

安裝教程

https://gradle.org/install/

Installing with a package manager

SDKMAN! is a tool for managing parallel versions of multiple Software Development Kits on most Unix-based systems.

代码语言:javascript
复制
$ sdk install gradle 6.6.1

Homebrew is “the missing package manager for macOS”.

代码语言:javascript
复制
$ brew install gradle

Other package managers are available, but the version of Gradle distributed by them is not controlled by Gradle, Inc. Linux package managers may distribute a modified version of Gradle that is incompatible or incomplete when compared to the official version (available from SDKMAN! or below).

› Additional helpful information

Installing manually

Step 1. Download the latest Gradle distribution

The current Gradle release is version 6.6.1, released on 25 Aug 2020. The distribution zip file comes in two flavors:

If in doubt, choose the binary-only version and browse docs and sources online.

Need to work with an older version? See the releases page.

Step 2. Unpack the distribution
Linux & MacOS users

Unzip the distribution zip file in the directory of your choosing, e.g.:

代码语言:javascript
复制
$ mkdir /opt/gradle
$ unzip -d /opt/gradle gradle-6.6.1-bin.zip
$ ls /opt/gradle/gradle-6.6.1
LICENSE  NOTICE  bin  getting-started.html  init.d  lib  media
Microsoft Windows users

Create a new directory C:\Gradle with File Explorer.

Open a second File Explorer window and go to the directory where the Gradle distribution was downloaded. Double-click the ZIP archive to expose the content. Drag the content folder gradle-6.6.1 to your newly created C:\Gradle folder.

Alternatively you can unpack the Gradle distribution ZIP into C:\Gradle using an archiver tool of your choice.

Step 3. Configure your system environment
Linux & MacOS users

Configure your PATH environment variable to include the bin directory of the unzipped distribution, e.g.:

代码语言:javascript
复制
 $ export PATH=$PATH:/opt/gradle/gradle-6.6.1/bin
Microsoft Windows users

In File Explorer right-click on the This PC (or Computer) icon, then click Properties -> Advanced System Settings -> Environmental Variables.

Under System Variables select Path, then click Edit. Add an entry for C:\Gradle\gradle-6.6.1\bin. Click OK to save.

Step 4. Verify your installation

Open a console (or a Windows command prompt) and run gradle -v to run gradle and display the version, e.g.:

代码语言:javascript
复制
$ gradle -v

------------------------------------------------------------
Gradle 6.6.1
------------------------------------------------------------
› Additional helpful information

Upgrade with the Gradle Wrapper

If your existing Gradle-based build uses the Gradle Wrapper, you can easily upgrade by running the wrapper task, specifying the desired Gradle version:

代码语言:javascript
复制
$ ./gradlew wrapper --gradle-version=6.6.1 --distribution-type=bin

Note that it is not necessary for Gradle to be installed to use the Gradle wrapper. The next invocation of gradlew or gradlew.bat will download and cache the specified version of Gradle.

代码语言:javascript
复制
$ ./gradlew tasks
Downloading https://services.gradle.org/distributions/gradle-6.6.1-bin.zip
...
› Additional helpful information

Older Releases

You can find all releases and their checksums on the releases page.

Command-Line Completion

Command-line completion scripts are available for bash and zsh. This provides completion for Gradle tasks and command-line options.

代码语言:javascript
复制
/elasticsearch$ gradle -v

------------------------------------------------------------
Gradle 6.6.1
------------------------------------------------------------

Build time:   2020-08-25 16:29:12 UTC
Revision:     f2d1fb54a951d8b11d25748e4711bec8d128d7e3

Kotlin:       1.3.72
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM:          11.0.8 (Oracle Corporation 11.0.8+10-LTS)
OS:           Mac OS X 10.14.5 x86_64

參考資料

「1」https://www.cnblogs.com/jpfss/p/9877862.html

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Gradle 命令行
    • 直接gradle
      • gradle build
        • gradle run
          • gradle check
            • gradle clean
              • gradle projects
                • gradle tasks
                  • gradle -q help –task xxx
                    • gradle buildEnvironment
                      • gradle dependencyInsight
                        • gradle model
                          • gradle dependencies
                          • 安裝教程
                            • Installing with a package manager
                              • Installing manually
                                • Upgrade with the Gradle Wrapper
                                  • Older Releases
                                    • Command-Line Completion
                                    • 參考資料
                                    相关产品与服务
                                    Elasticsearch Service
                                    腾讯云 Elasticsearch Service(ES)是云端全托管海量数据检索分析服务,拥有高性能自研内核,集成X-Pack。ES 支持通过自治索引、存算分离、集群巡检等特性轻松管理集群,也支持免运维、自动弹性、按需使用的 Serverless 模式。使用 ES 您可以高效构建信息检索、日志分析、运维监控等服务,它独特的向量检索还可助您构建基于语义、图像的AI深度应用。
                                    领券
                                    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档