成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

gradle-學(xué)習(xí)筆記(1)-初步使用

frank_fun / 1133人閱讀

摘要:最近想深入的學(xué)習(xí)一下工程化方面相關(guān)的東西,在和直接糾結(jié)不已,因?yàn)榈臄U(kuò)展性太差勁了,學(xué)習(xí)成本頗高,所以最后投入了的懷抱中,以后有時間再重新學(xué)習(xí)一下吧最近的學(xué)習(xí)筆記是基于系列,其中各種教程和例子大都是來源于官方文檔或者網(wǎng)絡(luò)上的博客。

最近想深入的學(xué)習(xí)一下工程化方面相關(guān)的東西,在maven和gradle直接糾結(jié)不已,因?yàn)閙aven的擴(kuò)展性太差勁了,學(xué)習(xí)成本頗高,所以最后投入了gradle的懷抱中,以后有時間再重新學(xué)習(xí)一下maven吧

最近的學(xué)習(xí)筆記是基于gradle 5 系列,其中各種教程和例子大都是來源于官方文檔或者網(wǎng)絡(luò)上的博客。內(nèi)容涵蓋我在學(xué)習(xí)gradle過程中的各種心得和gradle的一些使用方法

注意: 這里使用的配偶語言世kotlin 而不是使用groovy

gradle創(chuàng)建項(xiàng)目

一個命令

gradle init

用戶可以通過這個命令創(chuàng)建一個基本的gradle項(xiàng)目包括gradle項(xiàng)目的目錄結(jié)構(gòu)

├── build.gradle (1)
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar (2)
│       └── gradle-wrapper.properties (3)
├── gradlew (4)
├── gradlew.bat (5)  
└── settings.gradle (6)  

(1) gradle 的構(gòu)建腳本用來構(gòu)建當(dāng)前的gradle項(xiàng)目,最核心的配置文件

(2) (3) 一個gradle副本和配置文件,用來當(dāng)如果系統(tǒng)中的gradle版本和項(xiàng)目使用的gradle版本不同,將會在這里下載一個項(xiàng)目中的版本

(4) (5) 配套使用的命令行工具 沒有.bat后綴的是unix系統(tǒng)命令有的是windowns系統(tǒng),可以用來執(zhí)行g(shù)radle中定義的各種task 任務(wù)

(6) 用于配置Gradle構(gòu)建的Gradle設(shè)置腳本

gradle的task

gradle 方便用戶進(jìn)行配置的特性是源于gradle提供了方便使用task參數(shù)
這里編寫一個很基本的copy文件的權(quán)限,在路徑中添加一個src文件夾和dest文件夾,在src文件中添加一個文件markfile.txt 并且里面有一個內(nèi)容hello world!

然后在build.gradle 中編寫一個任務(wù)

task copy(type:Copy,group:"custom",description:"test one"){
    from "src"
    into "dest"
}

其中的type 字段將會調(diào)用系統(tǒng)中的Copy函數(shù),而group和description 只是描述這個過程的描述符,只會影響系統(tǒng)的log輸出,并不會影響實(shí)際的效果

./gradlew Copy

運(yùn)行對應(yīng)的命令就能運(yùn)行對應(yīng)的copy方法

使用一個gradle內(nèi)部的插件系統(tǒng)

在項(xiàng)目中使用插件標(biāo)簽plugins添加指定的base插件到系統(tǒng)中

plugins {
    id "base"
}

然后在指定的位置我們添加一個插件(和任務(wù)的使用方法相同,我懷疑其實(shí)gradle的插件就是打包好的任務(wù))

task zip(type: Zip, group: "Archive", description: "Archives sources in a zip file") {
    from "src"
    setArchiveName "basic-demo-1.0.zip"
}

然后運(yùn)行對應(yīng)的命令,就可以在對應(yīng)的目錄 build/distributions 中找到 src目錄下的壓縮文件了

./gradlew Zip
查看當(dāng)前擁有的task

gradle 有一個內(nèi)置的命令

./gradlew task

這條命令將會將所有的當(dāng)前的gradle項(xiàng)目中擁有的構(gòu)建命令全部列出來

> Task :tasks

------------------------------------------------------------
Tasks runnable from root project
------------------------------------------------------------

Archive tasks
-------------
zip - Archives sources in a zip file

Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
clean - Deletes the build directory.

Build Setup tasks
-----------------
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.

Custom tasks
------------
copy - Copies sources to the dest directory

Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project "gradle".
components - Displays the components produced by root project "gradle". [incubating]
dependencies - Displays all dependencies declared in root project "gradle".
dependencyInsight - Displays the insight into a specific dependency in root project "gradle".
dependentComponents - Displays the dependent components of components in root project "gradle". [incubating]
help - Displays a help message.
model - Displays the configuration model of root project "gradle". [incubating]
projects - Displays the sub-projects of root project "gradle".
properties - Displays the properties of root project "gradle".
tasks - Displays the tasks runnable from root project "gradle".

Verification tasks
------------------
check - Runs all checks.

Rules
-----
Pattern: clean: Cleans the output files of a task.
Pattern: build: Assembles the artifacts of a configuration.
Pattern: upload: Assembles and uploads the artifacts belonging to a configuration.

To see all tasks and more detail, run gradlew tasks --all

To see more detail about a task, run gradlew help --task 

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed
<-------------> 0% WAITING
> IDLE
gradle 提供的在線查看構(gòu)建詳情的方法 --scan命令

我們在使用構(gòu)建命令的時候可以在命令的后面添加一個 --scan命令,通過這個命令可以鏈接到gradle官方的view顯示倉庫或者連接到自定義的鏈接倉庫中,然后輕松的查看項(xiàng)目使用的構(gòu)建任務(wù),構(gòu)建時間等等信息

./gradlew Zip --scan

然后可以登入命令行打出的一個網(wǎng)址,在其中的form表單中填寫郵箱地址,然后就會將構(gòu)建的信息發(fā)送到郵箱中了

注意:這個功能是收費(fèi)的
gradle 展示當(dāng)前系統(tǒng)的可用參數(shù)信息 properties命令
$ ./gradlew properties
> Task :properties

------------------------------------------------------------
Root project
------------------------------------------------------------

buildDir: /Users/.../basic-demo/build
buildFile: /Users/.../basic-demo/build.gradle
description: null
group:
name: basic-demo
projectDir: /Users/.../basic-demo
version: unspecified

BUILD SUCCESSFUL

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/73432.html

相關(guān)文章

  • Gradle學(xué)習(xí)筆記 使用Gradle Wrapper

    摘要:可以在沒有安裝的情況下使用,這時候就需要了。創(chuàng)建文件使用來創(chuàng)建一組文件。官方建議我們在所有項(xiàng)目中都創(chuàng)建文件,方便沒有安裝的用戶使用。代碼如下然后使用來查看變更之后的版本。不過只需要下載一次,之后再次使用相同的版本就不會下載了。 Gradle可以在沒有安裝Gradle的情況下使用,這時候就需要Gradle Wrapper了。Gradle Wrapper其實(shí)就是一個腳本文件,它會在沒有安裝...

    Richard_Gao 評論0 收藏0
  • gradle-學(xué)習(xí)筆記(2)-多項(xiàng)目構(gòu)建

    摘要:記得在中支持多個子項(xiàng)目的構(gòu)建方法同樣的在中也會支持多項(xiàng)目的構(gòu)建方法還記得在中如何配置多項(xiàng)目工程嗎這里回憶一下首先我們需要一個父元素文件比如這樣而在中我們并不需要指定父元素的標(biāo)簽我們只需要編寫好對應(yīng)的文件夾名稱,并且將文件夾名稱和對 記得在maven中支持多個子項(xiàng)目的構(gòu)建方法,同樣的在gradle 中也會支持多項(xiàng)目的構(gòu)建方法 還記得在maven中如何配置多項(xiàng)目工程嗎, 這里回憶一下 首先...

    happen 評論0 收藏0
  • Gradle學(xué)習(xí)筆記1)創(chuàng)建簡單的Java項(xiàng)目

    摘要:是一個基于和概念的項(xiàng)目自動化構(gòu)建工具。當(dāng)前其支持的語言限于和主要面向應(yīng)用。本次分享將具體講述如何利用來創(chuàng)建一個簡單的項(xiàng)目。首先我們新建一個文件夾作為展示的項(xiàng)目。中的代碼如下這是用來定義項(xiàng)目。接著創(chuàng)建文件夾,這是項(xiàng)目開發(fā)中習(xí)慣性的構(gòu)建方法。 ??Gradle是一個基于Apache Ant和Apache Maven概念的項(xiàng)目自動化構(gòu)建工具。它使用一種基于Groovy的特定領(lǐng)域語言(DSL)...

    URLOS 評論0 收藏0
  • 鴻蒙學(xué)習(xí)筆記之初運(yùn)項(xiàng)目

    摘要:項(xiàng)目結(jié)構(gòu)下面是我們創(chuàng)建項(xiàng)目生成的目錄展開目錄如下配置文件,由系統(tǒng)自動生成,一般情況下不需要進(jìn)行修改開發(fā)工具的信息默認(rèn)啟動模塊主模塊,開發(fā)者用于編寫源碼文件以及開發(fā)資源文件的目錄用于存放模塊的依賴文件用于存放源碼用于存放應(yīng)用所用到的資源文件 1.項(xiàng)目結(jié)構(gòu) 下面是我們創(chuàng)建項(xiàng)目生成的目錄 1.M...

    不知名網(wǎng)友 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<