Top Banner
17

Gradle basics

Feb 17, 2017

Download

Engineering

Pedro Borrayo
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Gradle basics
Page 2: Gradle basics

Gradle build scripts are not written in the traditional XML, but in a domain-specific language (DSL) based on GroovyThat does not mean you need to know Groovy to get started with your build scripts.

Page 3: Gradle basics

• Initialization: This is where the Project instance is created. If there are multiple modules each of them must have their own build.gradle file.

• Configuration: creating and configuring all the tasks for every project object.

• Execution: Which tasks should be executed depends on the arguments passed for starting the build and what the current directory is.

Page 4: Gradle basics
Page 5: Gradle basics
Page 6: Gradle basics

Working with Repositories

http://jcenter.bintray.com/http://mvnrepository.com/http://search.maven.org/

Central and jcenter

Maven repositories

Ivy repositories

Page 7: Gradle basics

Artifacts

Must include the appropriate meta data. Can be identified and retrieved by a unique set of coordinates.If an artifact has dependencies of its own, that is also specified.

Page 8: Gradle basics

Declaring Dependencies

specific dependency

Group of dependencies

File Collection

File Tree

Page 9: Gradle basics

Test dependency

Commands

Page 10: Gradle basics

Tasks A task represents some atomic piece of work which a build performs. This might be compiling some classes, creating a JAR, generating Javadoc, or publishing some archives to a repository.

Page 11: Gradle basics

task count << { 4.times { println "$it " }}

task upper << { String someString = 'mY_nAmE' println "Original: " + someString println "Upper case: " + someString.toUpperCase()}

task hellos << { println ’Hello'}hellos.doFirst { println ’Fist Hello'}hellos.doLast { println ’Last Hello'}hellos << { println ‘Last Hello shortcut'}

task putOnSocks { doLast { println "Putting on Socks." }}

task putOnShoes { dependsOn "putOnSocks" doLast { println "Putting on Shoes." }}

task eatBreakfast { finalizedBy "brushYourTeeth" doLast{ println "Om nom nom breakfast!" }}

task brushYourTeeth { doLast { println "Brushie Brushie Brushie." }}

Page 12: Gradle basics

task takeShower { doLast { println "Taking a shower." }}

task putOnFragrance { shouldRunAfter "takeShower" doLast{ println "Smellin' fresh!" }}

task getReady { // Remember that when assigning a collection to a property, we need the // equals sign dependsOn = ["takeShower", "eatBreakfast", "putOnShoes"]}

4.times { counter -> task "task$counter" << { println "I'm task number $counter" }}task0.dependsOn task1, task2, task3

task copyDocs(type: Copy) { from '/Users/pborrayo/GradlePJ/images' include "*.*" into '/Users/pborrayo/GradlePJ/banners'}

./gradlew -q

Page 13: Gradle basics

Typed Tasks

Interacting With The File SystemTroubleshooting and LoggingCustom TaskIncremental BuildsParameterising Your BuildGradle DSL ReferencesLocating tasks

Page 14: Gradle basics

Build Type and a Product Flavor. The two are mechanically similar, but conceptually orthogonal. Build Types are typically transparent to users and are only important to you as a developer, whereas Product Flavors control features that are visible to end users. Build Types are used to control how our app is built and packaged. By default, every Android app has two Build Types, debug and release.

Page 15: Gradle basics

the Android Gradle plugin makes is very simple for us to declare product flavors for our app. Additionally, we've learned that the Android plugin creates source sets for each of our flavors, automatically. These source sets work just like source sets for regular Java projects. In additional to having unique source directories for each source set, we can also assign them unique dependencies.

Page 16: Gradle basics
Page 17: Gradle basics

http://michael-huang.logdown.com/posts/293691-building-java-with-gradle

https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Copy.html

Links suggestions