<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 1.用腳本創建目錄 通常情況下,創建目錄使用mkdir來創建目錄,但是有一種更好的方式來做到,避免每次都手動創建。定義一個任務來創建目錄,然后用dependsOn來依賴該任務,這有可以在需要的時候創建目錄。 ~~~ def classesDir = new File('build/classes') task resources << { classesDir.mkdirs() } task compile(dependsOn:'resources')<<{ if(classesDir.isDirectory()){ println 'The class directory exists.I canoperate' } } ~~~ 執行compile任務 ~~~ qianhuis-Mac-mini:0111 qianhui$ gradle -q compile The class directory exists.I canoperate ~~~ 然后就會在該目錄下生成build/classes目錄 ![](https://box.kancloud.cn/2016-01-07_568e46678dbda.jpg) ## 2.gradle屬性和系統屬性 有3種方式添加屬性,命令行中的-P和-D參數,以及屬性文件gradle.properties **通過命令行中的-P命令傳遞屬性。首先build.gradle定義屬性** ~~~ task printProps <<{ println commandLineProjectProp } ~~~ 在命令行中執行該命令,如果不帶參數會出錯。 ~~~ ~~~ qianhuis-Mac-mini:0111 qianhui$ gradle -q printProps FAILURE: Build failed with an exception. * Where: Build file '/Users/qianhui/Documents/Developer/gradle_project/0111/build.gradle' line: 2 * What went wrong: Execution failed for task ':printProps'. > Could not find property 'commandLineProjectProp' on task ':printProps'. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. ~~~ ~~~ gradle -q printProps -PcommandLineProjectProp=thisisacommandlineprop ~~~ 輸出如下 ~~~ qianhuis-Mac-mini:0111 qianhui$ gradle -q printProps -PcommandLineProjectProp=thisisacommandlineprop thisisacommandlineprop ~~~ 上面的寫法一定要注意,-P后面也可以有空格,執行的效果是一樣的。 ~~~ qianhuis-Mac-mini:0111 qianhui$ gradle -q printProps -P commandLineProjectProp=thisisacommandlineprop thisisacommandlineprop ~~~ 但是等號(=)兩端不能有空格,且屬性值也不能有空格。但是如果你用單引號 或者雙引號包裹的話可以有空格。 ~~~ qianhuis-Mac-mini:0111 qianhui$ gradle -q printProps -P commandLineProjectProp =this is acommandlineprop FAILURE: Build failed with an exception. * What went wrong: Task '=this' not found in root project '0111'. * Try: Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. ~~~ 用單引號或雙引號包裹 ~~~ qianhuis-Mac-mini:0111 qianhui$ gradle -q printProps -P commandLineProjectProp='this is a commandline prop' this is a commandline prop ~~~ ~~~ qianhuis-Mac-mini:0111 qianhui$ gradle -q&nbsp; printProps -P commandLineProjectProp="this is a commandline prop" this is a commandline prop ~~~ **-D添加gradle屬性。** build.gradle文件如下 如果這個時候我們還想剛才那樣執行命令的話,會報錯 ~~~ qianhuis-Mac-mini:0111 qianhui$ gradle -q printProps -P commandLineProjectProp="this is a commandline prop" this is a commandline prop FAILURE: Build failed with an exception. * Where: Build file '/Users/qianhui/Documents/Developer/gradle_project/0111/build.gradle' line: 3 * What went wrong: Execution failed for task ':printProps'. > Could not find property 'systemProjectProp' on task ':printProps'. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. ~~~ 說明build.gradle定義的systemProjectProp不存在,這個時候就需要用-D來添加gradle屬性 ~~~ qianhuis-Mac-mini:0111 qianhui$ gradle -q printProps -P commandLineProjectProp="this is a commandline prop" -D org.gradle.project.systemProjectProp="this a gradle property" this is a commandline prop this a gradle property ~~~ **gradle.properties文件添加屬性** build.gradle文件添加一個屬性 ~~~ task printProps <<{ println commandLineProjectProp println systemProjectProp println gradleFileProperties } ~~~ 這個時候執行命令,會報錯 ~~~ qianhuis-Mac-mini:0111 qianhui$ gradle -q printProps -P commandLineProjectProp="this is a commandline prop" -D org.gradle.project.systemProjectProp="this a gradle property" this is a commandline prop this a gradle property FAILURE: Build failed with an exception. * Where: Build file '/Users/qianhui/Documents/Developer/gradle_project/0111/build.gradle' line: 4 * What went wrong: Execution failed for task ':printProps'. > Could not find property 'gradleFileProperties' on task ':printProps'. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. ~~~ 在gradle.properties 文件中添加屬性 ~~~ gradleFileProperties = gradleFileProperties ~~~ 這個時候執行命令 ~~~ qianhuis-Mac-mini:0111 qianhui$ gradle -q printProps -P commandLineProjectProp="this is a commandline prop" -D org.gradle.project.systemProjectProp="this a gradle property" this is a commandline prop this a gradle property gradleFileProperties ~~~ ## 3.包含其他構建腳本 gradle 允許你包含其他構建的腳本,比如一些模版腳本,這樣的擴展性挺好。 定義一個模版腳本:template.gradle ~~~ task hello <<{ println "this a template" } ~~~ 然后在build.gradle腳本中包含改腳本 ~~~ apply from:'template.gradle' ~~~ 執行任務hello ~~~ qianhuis-Mac-mini:0111 qianhui$ gradle -q hello this a template ~~~ ## 4.自定義對象 ~~~ task configure <<{ def pos = configure(new java.text.FieldPosition(10)){ beginIndex = 1 endIndex = 5 } println pos.beginIndex println pos.endIndex } ~~~ ## 5.使用外部的腳本自定義對象 template.gradle修改如下: ~~~ beginIndex = 1 endIndex = 5 ~~~ build.gradle修改如下 ~~~ task configure <<{ def pos = new java.text.FieldPosition(10) apply from:'template.gradle',to:pos println pos.beginIndex println pos.endIndex } ~~~ 其中的apply from:'template.gradle',to :pos將template的屬性注入到pos對象中。執行命令后,輸出是一樣的。 ~~~ qianhuis-Mac-mini:0111 qianhui$ gradle -q configure 1 5 ~~~ ## 6.緩存 gradle創建了一個.gradle目錄用來緩存編譯的腳本。只有變換的時候,才會重新生成緩存的腳本。
                  <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>

                              哎呀哎呀视频在线观看