gradlefx

35
GradleFx Flex Build Tool By Yennick Trevels & Steven Dick

Upload: christophe-herreman

Post on 26-Jan-2015

102 views

Category:

Technology


0 download

DESCRIPTION

Belgian Flex Usergroup presentation by Yennick Trevels from the GradleFX team.

TRANSCRIPT

Page 1: GradleFX

GradleFxFlex Build Tool

By Yennick Trevels & Steven Dick

Page 2: GradleFX

Yennick TrevelsiDA MediaFoundryJava & Flex

Free TimeProgramming

ReadingGaming

@SlevinBE

Page 3: GradleFX

GradleAn introduction

Page 4: GradleFX

GradleFeatures

Convention over ConfigurationMulti-project supportDependency ManagementGroovy scriptingSource file change detection

Page 5: GradleFX

Gradle

Examplesubprojects { apply plugin: 'gradlefx'

version = '1.0-SNAPSHOT'

repositories { mavenCentral() mavenRepo name: 'yoolab-releases', url: "http://projects.yoolab.org/maven/content/repositories/releases" mavenRepo name: 'yoolab-snapshots', url: "http://projects.yoolab.org/maven/content/repositories/snapshots" }

dependencies { external group: 'org.springextensions.actionscript', name: 'spring-actionscript-core', version: '1.2-SNAPSHOT', ext: 'swc' external group: 'org.as3commons', name: 'as3commons-collections', version: '1.1', ext: 'swc' external group: 'org.as3commons', name: 'as3commons-lang', version: ‘0.3.2', ext: 'swc'

external group: 'org.graniteds', name: 'granite-swc', version: '2.2.0.SP1', ext: 'swc' external group: 'org.graniteds', name: 'granite-essentials-swc', version: ‘2.2.0.SP1', ext: 'swc' }}

Page 6: GradleFX

Gradle

Projects

One or more projects per buildOne or more tasks per projectOne build.gradle file per project

Page 7: GradleFX

Gradle

SubprojectsProject structure

Settings file (settings.gradle)

include 'client', 'domain', 'util', 'assets‘

Configuration Injectionsubprojects {

apply plugin: 'gradlefx'version = '1.0-SNAPSHOT'repositories {

mavenCentral()}

}

Page 8: GradleFX

Gradle

Tasks

Block of code that defines part of a build

Create a new tasktask(showText, dependsOn: ‘projectB:compile’) << {

println “I’m executing after the compile task" }

Configure an existing Tasktask(copy, type: Copy) {

from(file('srcDir')) into(buildDir)

}

Page 9: GradleFX

Gradle

Tasks

Adding behaviourcompile.doLast {

println “Compilation complete" }

Executing a task>gradle showText

Page 10: GradleFX

Gradle

MethodsStructure build logic

task(showText) << { printList([‘john’, ‘Alfred’, ‘Elise’])

}

def printList(names) {names.each() { name ->

println name}

}

Page 11: GradleFX

Gradle

ClassesDefined in

build scriptrootProjectDir/buildSrc/src/main/standalone project

Page 12: GradleFX

Gradle

Custom task classclass CopyResources extends DefaultTask {

public CopyResources() { description = 'copies the resources to the build directory' }

@TaskAction def copyResources() { project.resourceDirs.each { resourceDir -> def fromLocation = project.file(resourceDir).path def toLocation = project.buildDir.path

logger.info('from ' + fromLocation + ' to ' + toLocation)

project.copy { from fromLocation into toLocation } } }}

Page 13: GradleFX

Gradle

Convention propertiesProperties exposed by pluginsSimple or complex propertiesHave a default value (convention)Can be overridden

Example:srcDirs = ['src/main/flex'] convention = [‘src/main/actionscript’]htmlWrapper.title = ‘My html wrapper page title‘ default = project name

Page 14: GradleFX

Gradle

Repositories

repositories { mavenCentral() mavenLocal() mavenRepo name: 'yoolab-releases', url: "http://projects.yoolab.org/maven/content/repositories/releases" mavenRepo name: 'yoolab-snapshots', url: "http://projects.yoolab.org/maven/content/repositories/snapshots"}

Page 15: GradleFX

Gradle

DependenciesLibraries/other projects used by a project

Library Dependencydependencies {

merged group: 'org.graniteds', name: 'granite-swc', version: graniteds_version, ext: 'swc‘}

Project Dependencymerged project(':projectname')

Page 16: GradleFX

Gradle

ConfigurationsBundles a set of dependenciesVaries between plugins

merged group: 'org.graniteds', name: 'granite-swc', version: graniteds_version, ext: 'swc‘

‘merged’ configuration

Page 17: GradleFX

Gradle

Three-phase build

InitializationDetermines projects for buildProject instance creation

Configuration phaseRuns build script of every projectConfigures project objects

Execution phaseExecute the tasks

ProjectInstance {name;

}

ProjectInstance {name = “my project” ;

}

Page 18: GradleFX

Gradle

Three-phase build

AfterEvaluateRuns after project is configured

project.afterEvaluate {project.description = project.name + “ is my sample project”

}

Page 19: GradleFX

Gradle

Ant supportAnt project importSupport for Ivy repositoriesRun Ant tasks with Gradle

Exampleant.java(jar: project.flexHome + '/lib/mxmlc.jar', dir: project.flexHome + '/frameworks', fork: true, resultproperty: ‘antResultProperty’, outputproperty: ‘antOutputProperty’) {

arg(value: ‘-keep-as3-metadata+=Autowired,RemoteClass’)}

println ant.properties[‘antOutputProperty’]

Page 20: GradleFX

Gradle

Maven supportSupport for Maven repositoriesMaven plugin for Java based projects

Page 21: GradleFX

Gradle

Gradle wrapperRun Gradle without installing Gradlebatch/shell script

How?task wrapper(type: Wrapper) {

gradleVersion = ‘1.0’}

simple/ gradlew gradlew.bat gradle/wrapper/ gradle-wrapper.jar gradle-wrapper.properties

Page 22: GradleFX

GradleFxFlex builds just got easier!

Page 23: GradleFX

SWC, SWF & AIRClean & copy resources tasksHtml wrapper generationFlexUnit support

GradleFxFeatures

Page 24: GradleFX

GradleFx

TaskscleancompilepackagecopyResourcespublishcreateHtmlWrappertest

Page 25: GradleFX

GradleFx

SetupFlex SDKCreate FLEX_HOME environment variable conventionORSet flexHome convention property custom configuration

Apply Pluginbuildscript { repositories { mavenCentral() }

dependencies { classpath group: 'org.gradlefx', name: 'gradlefx', version: '0.4.1' } }

apply plugin: 'gradlefx'

Page 26: GradleFX

GradleFx

Project typeDefines to which type of archive the sources will be compiled toConvention property typePossible values ‘swc’, ‘swf’ or ‘air’

Exampletype = ‘swc’

Page 27: GradleFX

GradleFx

Basic conventionssources src/main/actionscript (srcDirs property)resources src/main/resources (resourceDirs property)test sources src/test/actionscript (testDirs property)test resources src/test/resources (testResourceDirs property)

mxml main class Main.mxml in src/main/actionscript/ (mainClass property)build directory build (project.buildDir property)

Page 28: GradleFX

GradleFx

Some advanced propertiesCompiler optionsadditionalCompilerOptions propertyOne item per compiler option

additionalCompilerOptions = [ '-use-network=true',

'-locale=en_US', '-keep-as3-metadata+=Autowired,RemoteClass‘]

JVM optionsjvmArguments property

jvmArguments = ['-Xmx1024m','-Xms512m']

Page 29: GradleFX

GradleFx

Dependency managementConfigurationsMerged (-compiler.library-path)Internal (-compiler.include-libraries)External (-compiler.external-library-path)Rsl (-runtime-shared-library-path)Test

Exampleexternal group: 'org.as3commons', name: 'as3commons-eventbus', version: '1.1', ext: 'swc' merged group: 'org.graniteds', name: 'granite-swc', version: '2.2.0.SP1', ext: 'swc'

Page 30: GradleFX

GradleFx

AIR project required stepsCreate AIR descriptor fileConvention

"/src/main/actionscript/${project.name}.xml“Custom value

air.applicationDescriptor: "/src/main/flex/airdescriptor.xml“

CertificateNeeded to sign the AIR packagePKCS12 formatPassword required

Convention"${project.name}.p12“

Custom valueair.keystore: "certificate.p12“air.storepass = "mypassword"

Page 31: GradleFX

GradleFx

FlexUnit required stepsSpecify FlexUnit homeConvention

FLEXUNIT_HOME environment variableCustom value

flexUnit.home = 'c:/flexunit/4.1'

Specify Flash Player executableConvention

FLASH_PLAYER_EXE environment variableCustom value

flexunit.command = ‘c:/flashplayer/flashplayer_10.exe’

Specify FlexUnit ant task jar nameLocated in FlexUnit home directoryCustom value

flexUnit.antTasksJar = 'flexUnitTasks-4.1.0-8.jar'

Page 32: GradleFX

GradleFx

FlexUnit required stepsSpecify FlexUnit dependenciesdependencies { test files( "${flexUnit.home}/flexunit-4.1.0-8-flex_4.1.0.16076.swc",

"${flexUnit.home}/flexunit-uilistener-4.1.0-8-4.1.0.16076.swc", "${flexUnit.home}/flexunit-cilistener-4.1.0-8-4.1.0.16076.swc“)

}

Specify testRunner classtestClass = 'MyTestRunner.mxml'

Page 33: GradleFX

GradleFx

DEMO

Page 34: GradleFX

GradleFx

What’s to come?IDEA and Eclipse project generation supportAS3Doc generationFlex SDK maven artifact support?

Page 35: GradleFX

GradleFx

Where to go nextGradleFx site: https://github.com/GradleFx/GradleFx

Source: https://github.com/GradleFx/GradleFx

Documentation: https://github.com/GradleFx/GradleFx/wiki

Examples: https://github.com/GradleFx/GradleFx-Examples

Help & Support: http://gradlefx.tenderapp.com/home

Bug tracker: https://github.com/GradleFx/GradleFx/issues

Changelog: https://github.com/GradleFx/GradleFx/blob/master/CHANGELOG.textile