<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                **(以下所有內容都是根據[官方文檔](https://www.gradle.org/docs/current/userguide/userguide.pdf)學習。如果你對gradle有興趣,希望你能直接學習官方文檔,官方文檔是最權威的。而且這樣才能產生2份有意義的學習資料)** ## 1.執行多個任務 在命令行下,要想執行多個任務,可以在gradle關鍵字后面跟多個任務名,之間要用空格隔開,執行的順序按照你的輸入的順序執行。例如我們要執行編譯和測試的任務。可以在命令行下輸入: ~~~ D:\GRADLE~2\0109>gradle compile test :compile1 nihao :compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :compileTestJava UP-TO-DATE :processTestResources UP-TO-DATE :testClasses UP-TO-DATE :test UP-TO-DATE BUILD SUCCESSFUL Total time: 2.787 secs ~~~ 可以看出先執行compile,然后是test。那么如果我倒過來呢? ~~~ D:\GRADLE~2\0109>gradle test compile :compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :compileTestJava UP-TO-DATE :processTestResources UP-TO-DATE :testClasses UP-TO-DATE :test UP-TO-DATE :compile1 nihao BUILD SUCCESSFUL Total time: 2.819 secs ~~~ 還是這樣的順序,因為這個是gradle自帶的任務,肯定要按嚴格的順序執行。所以沒有說服力,我們現在寫一個自己的。 build.gradle ~~~ apply plugin:'java' task test1<<{ &nbsp;&nbsp; &nbsp;println "test1" } task compile1 <<{ &nbsp;&nbsp; &nbsp;println "compile1" } ~~~ 這個時候按不同的順序執行一下 ![](https://box.kancloud.cn/2016-01-07_568e4665ef73f.jpg) 這下驗證了上面的說法,確實是按照輸入的順序執行的。 ## 2.依賴任務 其實剛才我們讓test先執行,compile后執行的時候已經可以看出,gradle會將命令行中列舉的任務的依賴任務也執行了。不然先執行test肯定會報錯了,就是因為test任務依賴于compile等任務,所以我們執行test任務的時候,它的依賴任務會先被執行,然后才執行test任務,命令行的輸出看的很明顯。 而且被依賴的任務只會被執行一次。 ~~~ task compile1 <<{ println 'compiling source' } task compileTest1(dependsOn:compile1) <<{ println 'compiling unit tests' } task test1(dependsOn:[compile1,compileTest1])<<{ println 'running unit tests' } task dist1(dependsOn:[compile1,test1])<<{ println 'build the distribution' } ~~~ 看上面的例子,dist1依賴compile1和test1。然后test1又依賴compile1和compileTest1。疏導一下關系 dist1依賴:compile1、compileTest1 test1依賴:compile1、compileTest1 依據執行的順序與命令行的列舉順序有關,且被依賴的任務只會被執行一次的這兩個原則,思考一下輸出應該是什么樣子。 我的猜測是: ~~~ compiling source ~~~ ~~~ compiling unit tests ~~~ ~~~ running unit tests ~~~ ~~~ build the distribution ~~~ 看看對不對 ![](https://box.kancloud.cn/2016-01-07_568e466614ae5.jpg) 還好,蒙對了。 ## 3.排除任務 gradle提供了排除某個特定任務的語法,不執行所依賴的任務中的某個任務,來看一下命令 ~~~ gradle task1 -x task2 ~~~ 在執行task1任務時不執行task1所依賴的task2任務。而且只刪除task2有依賴,而task1沒有依賴的任務。 同樣我們來看看執行下面的命令 ~~~ gradle -q dist1 -x test1 ~~~ 考慮一下執行的結果。我自己先猜一下,刨除test1中的兩個依賴項目。就剩下了 ~~~ compiling source ~~~ ~~~ build the distribution ~~~ 驗證一下 ![](https://box.kancloud.cn/2016-01-07_568e466628d8c.jpg) ## 4.倔強的構建方式 默認情況下,gradle在構建過程中遇到錯誤會自動停止,這樣有些錯誤你無法一次性發現。但是你也可以去設置:即使遇到錯也要倔強的構建,不撞南墻不回頭。 這樣的話等執行完畢后,再把所有的錯誤都打印出來,是不是很好呢。使用--continue屬性。(這塊還不太清楚怎么使用,以后知道了再補充) ## 5.智能匹配 執行任務的時候,任務名不需要寫全,但是得能夠匹配唯一一個。 ~~~ task compile1 <<{ println 'compiling source' } task compileTest1 <<{ println 'compiling unit tests' } task test1<<{ println 'running unit tests' } task dist1<<{ println 'build the distribution' } task dist2 <<{ println 'dist2' } ~~~ 例如上面的任務,我們可以通過comile匹配compile1。但是dist就不能匹配dist1,因為還有一個dist2也匹配。執行的情況如下: ![](https://box.kancloud.cn/2016-01-07_568e4666397f9.jpg) 對于有2個單詞組成的任務名,我們可以通過首字母的縮寫匹配該任務。 ![](https://box.kancloud.cn/2016-01-07_568e466656967.jpg) ## 6.選擇特定的文件去執行 比如我們去執行同目錄下sob目錄下的的user.gradle構建文件。sob/user.gradle文件內容如下 ~~~ task hello<<{ println "using build file '$buildFile.name' in '$buildFile.parentFile.name'" } ~~~ 執行該文件 ~~~ D:\GRADLE~2\0109>gradle -q -b sob/user.gradle hello using build file 'user.gradle' in 'sob' ~~~ 可以看出要在命令行上用-b 后面跟目錄來表示指定的文件。任務在前或在后效果都是一樣的。 ~~~ D:\GRADLE~2\0109>gradle -q hello -b sob/user.gradle using build file 'user.gradle' in 'sob' ~~~
                  <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>

                              哎呀哎呀视频在线观看