Gradle Introduction
目錄
- Compileing development Process
- Old compile Mothed
- Modern compile Mothed
- What is Gradle
- Gradle Effect
- What is Groovy
- Groovy syntax reles
- Structure Script
- Peoject
- Attribute
- Task
- Example #1
- apply
- Example #1
- Example #2
- Dependency Management
- Example #1
- Example #2
- Multiple Porject Structure
- Testing
- Release
Compileing development Process
Old compile Mothed
1.Manually copy the jar to libs.
2.Manually copy the modules to libs.
3.2.Manually copy the aarto libs.
Modern compile Mothed
- maven
- Gradle
What is Gradle
Gradle is code dependency management tool.
Gradle base is Apache Ant and Apache Maven.
Gradle use Groovy language as the implementation.
For java domain.
Gradle Effect
I often use it:
- Dependency Management
- Code Compile
- Pack to APK
- Pack to Jar
I don't user it very often:
- Testing
- Automatic execution
- Release
Example # Android 新建工程階段
What is Groovy
Groovy is seemed Java that OOP language.
Groovy syntax reles
TODO.
Structure Script
Two base concept:
- project
- task
Peoject
每個構建中至少包含一個項目。
在多項目構建中,一個項目依賴于其他項目。
一個項目代表一個正在構建的組件(如一個jar文件),當構建啟動后,Gradle會給予build.gradle實例化一個org.gradle.api.Project類,并且能通過project變量使其隱式可用。
Attribute
- group
- name
- version
- apply
- dependencies
- repositories
- task
Task
一個項目至少包含一個或多個任務。
對應 org.gradle.api.Task類,主要包括任務動作和任務依賴。
任務動作定義了一個最小的工作單元,可以定義依賴于其他任務、動作序列和執行條件。
function:
- dependsOn
- doFirst
- doLast
- <<
Example #1
task task2{println "task2" }task1 <<{println "task1 append" }apply
apply plugin:'×××' //引入二進制插件 apply from:'×××' //引入應用腳本插件plugin effect:
- 模塊化構建腳本的功能
- 公共的功能可以抽取出來成為插件,可以供多個 build.gradle 使用,增加復用性
Example #1
1.創建一個 Java Library 的 module
2.定義一個接口
3.在外部引入二進制插件
//在 app 下的 build.gradle 引用這個插件 apply plugin: PluginTestExample #2
apply plugin: 'com.android.application'android {compileSdkVersion 25buildToolsVersion "25.0.1"}}在Andriod中有3類工程:
- App插件id:com.android.application
- Library插件id:com.android.library
- Test插件id:com.android.test
一般一個項目只會設置一個App插件,而module一般是會設置為Library插件。
Dependency Management
大部分基于JVM的軟件項目都需要依賴外部類庫來實現、重用現有功能。
自動化的依賴管理可以明確依賴的版本,解決因傳遞性依賴帶來的版本沖突。
- 明確依賴的版本
- 解決版本沖突
Concept:
工件坐標
工件 ≈ jar
坐標 ≈ group、name、version常用倉庫
公共倉庫:mavenLocal、mavenCentral(https://search.maven.org)、jcenter...
自定義倉庫:本地創建的包倉庫
文件倉庫: 保存本地文件路徑,不建議使用,容易沖突依賴的傳遞性
A<----B<----C<----D
Example #1
repositories{maven{url 'http://192.168.0.1' #自己私服的地址}mavenCentrral() #使用遠程倉庫mavenLoacl() #使用遠程倉庫 }dependencies{compile 'junit:junit:4.12' }Example #2
allprojects {repositories {jcenter()} } dependencies {compile fileTree(dir: 'libs', include: ['*.jar'])androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {exclude group: 'com.android.support', module: 'support-annotations'})compile 'com.android.support:appcompat-v7:25.3.0'testCompile 'junit:junit:4.12' }Multiple Porject Structure
TODO
Testing
TODO
Release
TODO
轉載于:https://www.cnblogs.com/mysticbinary/articles/11230367.html
總結
以上是生活随笔為你收集整理的Gradle Introduction的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mac中apache服务器及虚拟主机配置
- 下一篇: 博客园-我的新的开始