<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                本章介紹了 Gradle 命令行的基本知識。正如在前面的章節里你所見到的, 調用 gradle 命令來執行構建。 ## [](https://github.com/waylau/Gradle-2-User-Guide/blob/master/Chapter%2011.%20Using%20the%20Gradle%20Command-Line%20%E4%BD%BF%E7%94%A8%20Gradle%20%E5%91%BD%E4%BB%A4%E8%A1%8C.md#111-executing-multiple-tasks-執行多-task)11.1\. Executing multiple tasks 執行多 task 同個構建可以執行多個 task ,通過再命令行 列出每個 task。舉例,命令?`gradle compile test`?將會執行 compile 和 test 兩個 task。 Gradle 將會按順序執行 命令行每個列出的 task,并且執行每個 task 的依賴。每個任務僅執行一次,不管它是如何被包含在構建中:無論是在命令行中指定,或作為另一個 task 的依賴,或兩者都是。讓我們看一個例子。 下面定義了4個 task。 dist 和 test 都依賴于 compile 。執行?`gradle dist test`?,compile 將會僅僅被執行一次。 Figure 11.1\. Task dependencies [![](https://box.kancloud.cn/2015-08-19_55d480a70ada7.jpg)](https://box.kancloud.cn/2015-08-19_55d480a70ada7.jpg) Example 11.1\. Executing multiple tasks build.gradle ~~~ task compile << { println 'compiling source' } task compileTest(dependsOn: compile) << { println 'compiling unit tests' } task test(dependsOn: [compile, compileTest]) << { println 'running unit tests' } task dist(dependsOn: [compile, test]) << { println 'building the distribution' } ~~~ 執行 gradle dist test 輸出 ~~~ > gradle dist test :compile compiling source :compileTest compiling unit tests :test running unit tests :dist building the distribution BUILD SUCCESSFUL Total time: 1 secs ~~~ 每個 task 只執行一次,所以?`gradle test test`?跟?`gradle test`?執行結果一樣。 ## [](https://github.com/waylau/Gradle-2-User-Guide/blob/master/Chapter%2011.%20Using%20the%20Gradle%20Command-Line%20%E4%BD%BF%E7%94%A8%20Gradle%20%E5%91%BD%E4%BB%A4%E8%A1%8C.md#112-excluding-tasks-排除-task)11.2\. Excluding tasks 排除 task 可以通過 -x 命令行來排除 task 被執行。如下: Example 11.2\. Excluding tasks 執行 gradle dist -x test 輸出 ~~~ > gradle dist -x test :compile compiling source :dist building the distribution BUILD SUCCESSFUL ~~~ Total time: 1 secs 可以看到 ,test 并未執行,即使它是 dist 的依賴。同時注意到, test 的依賴,如 compileTest 也未執行。這些 test 的依賴如果是被其他 task 所需要的話,如 compile 仍會執行。 ## [](https://github.com/waylau/Gradle-2-User-Guide/blob/master/Chapter%2011.%20Using%20the%20Gradle%20Command-Line%20%E4%BD%BF%E7%94%A8%20Gradle%20%E5%91%BD%E4%BB%A4%E8%A1%8C.md#113-continuing-the-build-when-a-failure-occurs-發生故障時繼續構建)11.3\. Continuing the build when a failure occurs 發生故障時繼續構建 默認情況下,只要任何 task 失敗,Gradle 將中止執行。這使得構建更快地完成,但隱藏了其他可能發生的故障。為了發現在一個單一的構建中多個可能發生故障的地方,你可以使用 --continue 選項。 通過執行 --continue ,Gralde 會執行每一個 task ,當那個 task 所有的依賴都無故障的執行完成, 而不是一旦出現錯誤就會中斷執行。所有故障信息都會在最后報告出來。 一旦某個 task 執行失敗,那么所有依賴于該 task 的后面的 task 都不會被執行,因為這樣做不安全。例如,在測試時,當編譯代碼失敗則測試不會執行。因為 測試 task 將取決于 編譯 task(不管是直接或間接)。 ## [](https://github.com/waylau/Gradle-2-User-Guide/blob/master/Chapter%2011.%20Using%20the%20Gradle%20Command-Line%20%E4%BD%BF%E7%94%A8%20Gradle%20%E5%91%BD%E4%BB%A4%E8%A1%8C.md#114-task-name-abbreviation-任務名稱縮寫)11.4\. Task name abbreviation 任務名稱縮寫 當你試圖執行某個 task 的時候,無需輸入 task 的全名.只需提供足夠的可以唯一區分出該 task 的字符即可。例如,上面的例子你也可以這么寫, 用?`gradle di`?來直接調用 dist 。 Example 11.3\. Abbreviated task name 執行 gradle di ~~~ > gradle di :compile compiling source :compileTest compiling unit tests :test running unit tests :dist building the distribution BUILD SUCCESSFUL Total time: 1 secs ~~~ 同時也可以應用在駝峰的 task 名稱。如,執行 compileTest 時,運行 gradle compTest 或者 gradle cT 都可以。 Example 11.4\. Abbreviated camel case task name 執行 gradle cT ~~~ > gradle cT :compile compiling source :compileTest compiling unit tests BUILD SUCCESSFUL Total time: 1 secs ~~~ 同時,也可以應用在 -x 命令選項。 ## [](https://github.com/waylau/Gradle-2-User-Guide/blob/master/Chapter%2011.%20Using%20the%20Gradle%20Command-Line%20%E4%BD%BF%E7%94%A8%20Gradle%20%E5%91%BD%E4%BB%A4%E8%A1%8C.md#115-selecting-which-build-to-execute-選擇要執行的構建)11.5\. Selecting which build to execute 選擇要執行的構建 調用 gradle 命令時,默認情況下總是會在當前目錄下尋找構建文件(譯者注:首先會尋找當前目錄下的 build.gradle 文件,以及根據settings.gradle 中的配置尋找子項目的 build.gradle )。 可以使用 -b 參數選擇其他的構建文件,并且當你使用此參數時 settings.gradle 將不會被使用,看下面的例子: Example 11.5\. Selecting the project using a build file subdir/myproject.gradle ~~~ task hello << { println "using build file '$buildFile.name' in '$buildFile.parentFile.name'." } ~~~ 執行 gradle -q -b subdir/myproject.gradle hello 輸出 ~~~ > gradle -q -b subdir/myproject.gradle hello using build file 'myproject.gradle' in 'subdir'. ~~~ 或者,您可以使用 -p 選項來指定要使用的項目目錄。多 project 的構建時應使用 -p 選項來代替 -b 選項。 Example 11.6\. Selecting the project using project directory 執行 gradle -q -p subdir hello 輸出 ~~~ > gradle -q -p subdir hello using build file 'build.gradle' in 'subdir'. ~~~ ## [](https://github.com/waylau/Gradle-2-User-Guide/blob/master/Chapter%2011.%20Using%20the%20Gradle%20Command-Line%20%E4%BD%BF%E7%94%A8%20Gradle%20%E5%91%BD%E4%BB%A4%E8%A1%8C.md#116-obtaining-information-about-your-build-獲取構建信息)11.6\. Obtaining information about your build 獲取構建信息 Gradle 提供了許多內置 task 來收集構建信息。這些內置 task 對于了解依賴結構以及解決問題都是很有幫助的. 了解更多,可以參閱[Chapter 41\. The Project Report Plugin 關于 Project Report 插件](https://github.com/waylau/Gradle-2-User-Guide/blob/master/Chapter%2041.%20The%20Project%20Report%20Plugin%20%E5%85%B3%E4%BA%8E%20Project%20Report%20%E6%8F%92%E4%BB%B6.md),可以為你的項目添加構建報告 ### [](https://github.com/waylau/Gradle-2-User-Guide/blob/master/Chapter%2011.%20Using%20the%20Gradle%20Command-Line%20%E4%BD%BF%E7%94%A8%20Gradle%20%E5%91%BD%E4%BB%A4%E8%A1%8C.md#1161-listing-projects--項目列表)11.6.1\. Listing projects 項目列表 執行?`gradle projects`?會為你列出選中項目的子項目列表.如下例. Example 11.7\. Obtaining information about projects 執行 gradle -q projects 輸出 ~~~ > gradle -q projects ------------------------------------------------------------ Root project ------------------------------------------------------------ Root project 'projectReports' +--- Project ':api' - The shared API for the application \--- Project ':webapp' - The Web application implementation To see a list of the tasks of a project, run gradle <project-path>:tasks For example, try running gradle :api:tasks ~~~ 這份報告展示了每個項目的描述信息。當然你可以在項目中用 description屬性來指定這些描述信息。 Example 11.8\. Providing a description for a project build.gradle ~~~ description = 'The shared API for the application' ~~~ ### [](https://github.com/waylau/Gradle-2-User-Guide/blob/master/Chapter%2011.%20Using%20the%20Gradle%20Command-Line%20%E4%BD%BF%E7%94%A8%20Gradle%20%E5%91%BD%E4%BB%A4%E8%A1%8C.md#1162-listing-tasks-任務列表)11.6.2\. Listing tasks 任務列表 執行?`gradle tasks`?會列出項目中所有 task。這份報告顯示項目中所有的默認 task 以及每個 task 的描述。如下 Example 11.9\. Obtaining information about tasks 執行 gradle -q tasks 輸出 ~~~ > gradle -q tasks ------------------------------------------------------------ All tasks runnable from root project ------------------------------------------------------------ Default tasks: dists Build tasks ----------- clean - Deletes the build directory (build) dists - Builds the distribution libs - Builds the JAR Build Setup tasks ----------------- init - Initializes a new Gradle build. [incubating] wrapper - Generates Gradle wrapper files. [incubating] Help tasks ---------- components - Displays the components produced by root project 'projectReports'. [incubating] dependencies - Displays all dependencies declared in root project 'projectReports'. dependencyInsight - Displays the insight into a specific dependency in root project 'projectReports'. help - Displays a help message. projects - Displays the sub-projects of root project 'projectReports'. properties - Displays the properties of root project 'projectReports'. tasks - Displays the tasks runnable from root project 'projectReports' (some of the displayed tasks may belong to subprojects). To see all tasks and more detail, run with --all. ~~~ 默認情況下,這只會顯示那些被分組的 task.你可以通過為 task 設置group 屬性和 description 來把這些信息展示到報告中 Example 11.10\. Changing the content of the task report build.gradle ~~~ dists { description = 'Builds the distribution' group = 'build' } ~~~ 當然你也可以用 --all 參數來收集更多 task 信息。這報告列出項目中所有被主 task 的分組的 task 以及 task 之間的依賴關系。下面是示例 Example 11.11\. Obtaining more information about tasks 執行 gradle -q tasks --all 輸出 ~~~ > gradle -q tasks --all ------------------------------------------------------------ All tasks runnable from root project ------------------------------------------------------------ Default tasks: dists Build tasks ----------- clean - Deletes the build directory (build) api:clean - Deletes the build directory (build) webapp:clean - Deletes the build directory (build) dists - Builds the distribution [api:libs, webapp:libs] docs - Builds the documentation api:libs - Builds the JAR api:compile - Compiles the source files webapp:libs - Builds the JAR [api:libs] webapp:compile - Compiles the source files Build Setup tasks ----------------- init - Initializes a new Gradle build. [incubating] wrapper - Generates Gradle wrapper files. [incubating] Help tasks ---------- components - Displays the components produced by root project 'projectReports'. [incubating] api:components - Displays the components produced by project ':api'. [incubating] webapp:components - Displays the components produced by project ':webapp'. [incubating] dependencies - Displays all dependencies declared in root project 'projectReports'. api:dependencies - Displays all dependencies declared in project ':api'. webapp:dependencies - Displays all dependencies declared in project ':webapp'. dependencyInsight - Displays the insight into a specific dependency in root project 'projectReports'. api:dependencyInsight - Displays the insight into a specific dependency in project ':api'. webapp:dependencyInsight - Displays the insight into a specific dependency in project ':webapp'. help - Displays a help message. api:help - Displays a help message. webapp:help - Displays a help message. projects - Displays the sub-projects of root project 'projectReports'. api:projects - Displays the sub-projects of project ':api'. webapp:projects - Displays the sub-projects of project ':webapp'. properties - Displays the properties of root project 'projectReports'. api:properties - Displays the properties of project ':api'. webapp:properties - Displays the properties of project ':webapp'. tasks - Displays the tasks runnable from root project 'projectReports' (some of the displayed tasks may belong to subprojects). api:tasks - Displays the tasks runnable from project ':api'. webapp:tasks - Displays the tasks runnable from project ':webapp'. ~~~ ### [](https://github.com/waylau/Gradle-2-User-Guide/blob/master/Chapter%2011.%20Using%20the%20Gradle%20Command-Line%20%E4%BD%BF%E7%94%A8%20Gradle%20%E5%91%BD%E4%BB%A4%E8%A1%8C.md#1163-show-task-usage-details-顯示-task-使用細節)11.6.3\. Show task usage details 顯示 task 使用細節 執行 gradle help --task someTask 可以獲取到 task 的詳細信息, 或者多項目構建中相同 task 名稱的所有 task 的信息,如下 Example 11.12\. Obtaining detailed help for tasks 執行 gradle -q help --task libs 輸出 ~~~ > gradle -q help --task libs Detailed task information for libs Paths :api:libs :webapp:libs Type Task (org.gradle.api.Task) Description Builds the JAR ~~~ 這些結果包含了完整的 task 的路徑、類型、可能的命令行選項以及描述信息等. ### [](https://github.com/waylau/Gradle-2-User-Guide/blob/master/Chapter%2011.%20Using%20the%20Gradle%20Command-Line%20%E4%BD%BF%E7%94%A8%20Gradle%20%E5%91%BD%E4%BB%A4%E8%A1%8C.md#1164-listing-project-dependencies-依賴列表)11.6.4\. Listing project dependencies 依賴列表 執行 gradle dependencies 會列出項目的依賴列表,所有依賴會根據任務區分,以樹型結構展示出來。如下 Example 11.13\. Obtaining information about dependencies 執行 gradle -q dependencies api:dependencies webapp:dependencies 輸出 ~~~ > gradle -q dependencies api:dependencies webapp:dependencies ------------------------------------------------------------ Root project ------------------------------------------------------------ No configurations ------------------------------------------------------------ Project :api - The shared API for the application ------------------------------------------------------------ compile \--- org.codehaus.groovy:groovy-all:2.3.6 testCompile \--- junit:junit:4.11 \--- org.hamcrest:hamcrest-core:1.3 ------------------------------------------------------------ Project :webapp - The Web application implementation ------------------------------------------------------------ compile +--- project :api | \--- org.codehaus.groovy:groovy-all:2.3.6 \--- commons-io:commons-io:1.2 testCompile No dependencies ~~~ 由于依賴的報告可以變得較大,可以使用特定的配置來限制到一個有用的報告。可以通過 --configuration 可選參數來實現。 Example 11.14\. Filtering dependency report by configuration 執行 gradle -q api:dependencies --configuration testCompile 輸出為 ~~~ > gradle -q api:dependencies --configuration testCompile ------------------------------------------------------------ Project :api - The shared API for the application ------------------------------------------------------------ testCompile \--- junit:junit:4.11 \--- org.hamcrest:hamcrest-core:1.3 ~~~ ### [](https://github.com/waylau/Gradle-2-User-Guide/blob/master/Chapter%2011.%20Using%20the%20Gradle%20Command-Line%20%E4%BD%BF%E7%94%A8%20Gradle%20%E5%91%BD%E4%BB%A4%E8%A1%8C.md#1165-getting-the-insight-into-a-particular-dependency-查看特定依賴)11.6.5\. Getting the insight into a particular dependency 查看特定依賴 執行 gradle dependencyInsight 可以查看指定的依賴情況,如下 Example 11.15\. Getting the insight into a particular dependency 執行 gradle -q webapp:dependencyInsight --dependency groovy --configuration compile 輸出 ~~~ > gradle -q webapp:dependencyInsight --dependency groovy --configuration compile org.codehaus.groovy:groovy-all:2.3.6 \--- project :api \--- compile ~~~ 這對于分辨依賴、了解依賴關系、了解為何選擇此版本作為依賴十分有用。了解更多請參閱?[DependencyInsightReportTask](http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.diagnostics.DependencyInsightReportTask.html)類的 API 內建的 dependencyInsight 是'Help' task 分組中的一個。這項 task 需要進行依賴和配置文件的配置才可以。該報告尋找那些與定依賴規范指定的配置匹配的的依賴。如果應用了 Java 相關的插件,該dependencyinsight task 是預先經過 'compile' 配置,因為它通常依賴我們感興趣的編譯。你應該指定您感興趣的依賴,通過命令行 '--dependency'選項。如果你不喜歡默認的,你可以選擇通過 '--configuration' 選項來配置。更多信息見[DependencyInsightReportTask](http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.diagnostics.DependencyInsightReportTask.html)?類的API文檔。 ### [](https://github.com/waylau/Gradle-2-User-Guide/blob/master/Chapter%2011.%20Using%20the%20Gradle%20Command-Line%20%E4%BD%BF%E7%94%A8%20Gradle%20%E5%91%BD%E4%BB%A4%E8%A1%8C.md#1166-listing-project-properties-項目屬性列表)11.6.6\. Listing project properties 項目屬性列表 執行 gradle properties 可以獲取項目所有屬性列表,如下 Example 11.16\. Information about properties 執行 gradle -q api:properties 輸出 ~~~ > gradle -q api:properties ------------------------------------------------------------ Project :api - The shared API for the application ------------------------------------------------------------ allprojects: [project ':api'] ant: org.gradle.api.internal.project.DefaultAntBuilder@12345 antBuilderFactory: org.gradle.api.internal.project.DefaultAntBuilderFactory@12345 artifacts: org.gradle.api.internal.artifacts.dsl.DefaultArtifactHandler_Decorated@12345 asDynamicObject: org.gradle.api.internal.ExtensibleDynamicObject@12345 baseClassLoaderScope: org.gradle.api.internal.initialization.DefaultClassLoaderScope@12345 buildDir: /home/user/gradle/samples/userguide/tutorial/projectReports/api/build buildFile: /home/user/gradle/samples/userguide/tutorial/projectReports/api/build.gradle ~~~ ### [](https://github.com/waylau/Gradle-2-User-Guide/blob/master/Chapter%2011.%20Using%20the%20Gradle%20Command-Line%20%E4%BD%BF%E7%94%A8%20Gradle%20%E5%91%BD%E4%BB%A4%E8%A1%8C.md#1167-profiling-a-build)11.6.7\. Profiling a build --profile 命令選項可以記錄一些構建期間的信息并保存到 build/reports/profile 目錄下并且以構建時間命名這些文件 該報告列出總時間和在配置和 task 的執行 階段的細節。并以時間大小倒序排列,并且記錄了任務的執行情況 如果采用了 buildSrc 構建,那么在 buildSrc/build 下同時也會給 buildSrc 生成一份日志記錄 [![](https://box.kancloud.cn/2015-08-19_55d480aacedc5.jpg)](https://box.kancloud.cn/2015-08-19_55d480aacedc5.jpg) ## [](https://github.com/waylau/Gradle-2-User-Guide/blob/master/Chapter%2011.%20Using%20the%20Gradle%20Command-Line%20%E4%BD%BF%E7%94%A8%20Gradle%20%E5%91%BD%E4%BB%A4%E8%A1%8C.md#117-dry-run-干跑)11.7\. Dry Run 干跑 有時可能你只想知道某個 task 在一個 task 集中按順序執行的結果,但并不想實際執行這些 task 。那么你可以用 -m 選項。例如 執行?`gradle -m clean compile`?將會看到所有的作為 clean 和 compile 一部分的 task 會被執行。這與 task 可以形成互補,讓你知道哪些 task 可以用于執行。 ## [](https://github.com/waylau/Gradle-2-User-Guide/blob/master/Chapter%2011.%20Using%20the%20Gradle%20Command-Line%20%E4%BD%BF%E7%94%A8%20Gradle%20%E5%91%BD%E4%BB%A4%E8%A1%8C.md#118-summary-總結)11.8\. Summary 總結 本章看到了命令行的一部分。更多詳見?[Appendix D. Gradle Command Line 命令行](https://github.com/waylau/Gradle-2-User-Guide/blob/master/Appendix%20D.%20Gradle%20Command%20Line%20%E5%91%BD%E4%BB%A4%E8%A1%8C.md)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看