O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

An Introduction to Maven and Flex

6.662 visualizações

Publicada em

Introduction to building Flex and AIR applications with Maven through the open source Flexmojos plugin.

All source available: https://github.com/justinjmoses/flexmojos-introduction

Publicada em: Tecnologia

An Introduction to Maven and Flex

  2. 2. WHAT IS MAVEN?Automated build & dependency managementConvention over configurationRepositories - both local and remote - maintain dependenciesUses a pom.xml file to detail build instructionsHierarchical tree structures - each artifact can have a parent and Nchildren.Runs a series of phases in the project lifecycle, including compile, test,package and install
  3. 3. THE BUILD LIFECYCLEBuilds are made up of phases. Default lifecycle: Compile Test (build test classes and run) Package (package as single artifact) Install (install artifact locally) Deploy (upload artifact to remote repository)
  4. 4. WHAT IS FLEXMOJOS?A Maven plugin that manages the compilation, optimisation and testingof flex applications, modules and libraries.Open Source: github.com/Flexmojos/flexmojosWritten and maintained by @velobr
  5. 5. REPOSITORIESLocal repository is ~/.m2 (or under Users[You].m2 in Win7)Settings.xml file depicts machine-level settings - such as remoterepository locations.
  6. 6. NEXUSNexus is a repository managerOrganisations using Maven typically have their own internal NexusinstanceNexus can proxy to other Nexus repositoriesTwo types of repositories - Snapshot and Release
  7. 7. A SIMPLE FLEX APPLICATIONMinimum requirements: pom.xml to describe the build one or more source files
  8. 8. LOOKING AT THE POM<project> <modelVersion>4.0.0</modelVersion> <groupId>org.justinjmoses.maven</groupId> <artifactId>flexmojos-simplist</artifactId> <name>Simplist Flexmojos</name> <version>0.1-SNAPSHOT</version> <packaging>swf</packaging> <build> <sourceDirectory>src</sourceDirectory> <plugins> <!-- Details on the Flexmojos plugin --> <plugin> <groupId>org.sonatype.flexmojos</groupId> <artifactId>flexmojos-maven-plugin</artifactId> <version>4.0-RC1</version> <configuration> <sourceFile>./Main.swf</sourceFile> <swfVersion>12</swfVersion> </configuration> <dependencies> <dependency> <groupId>com.adobe.flex</groupId> <artifactId>compiler</artifactId> <version></version> <type>pom</type> </dependency> </dependencies> </plugin> </plugins> </build> <dependencies> ... list of dependencies for building/testing ... </dependencies></project>
  9. 9. VERSIONINGWhere to find dependencies and versions? Flexmojos Flex framework Others?
  10. 10. AUTOMATED UNIT TESTINGRequirements Standalone Flash Player Add test folders and tests (Test*.as default) Add test source location to your pom <testSourceDirectory>src/test</testSourceDirectory> Add Flexunit dependency to your pom <dependency> <groupId>com.adobe.flexunit</groupId> <artifactId>flexunit</artifactId> <version>4.0-rc-1</version> <type>swc</type> <scope>test</scope> </dependency>
  11. 11. ADDING DEPENDENCIESNot all dependencies are hosted remotely.Some have to be installed manually via install:install-file goal.> mvn install:install-file -Dfile=[file] -DgroupId=[groupId] -DartifactId=[artifactId] -Dversion=[version] -Dpackaging=swc
  12. 12. FROM SOURCE TO IDEFlexmojos has a goal to create Flashbuilder projects from Maven buildsCreate a basic pom and source/test structure, then run the goal> mvn org.sonatype.flexmojos:flexmojos-maven-plugin:3.9:flashbuilderNote: when using Maven, you do not check in your .project, .settings or libs to source control. TheFlashbuilder goal will create these settings for you.Why? Because your pom should be the definitive definition of the build - your project settings are only local toyour machine & environment.
  13. 13. ARCHETYPESMaven supports beginning projects using archetypes (templates)Flexmojos provides three main archetypes: library, application, modular application> mvn archetype:generate-DarchetypeRepository=http://repository.sonatype.com/content/groups/flexgroup-DarchetypeGroupId=org.sonatype.flexmojos-DarchetypeArtifactId=flexmojos-archetypes-application-DarchetypeVersion=4.0-RC1Typical prescription is the following folder structure `-- src |-- main | |-- flex | `-- resources `-- test |-- flex `-- resourcesArchetypes themselves are projects. You can create your own as templates for newprojects.
  14. 14. APPLICATIONS WITH LIBRARIES We can add a top-level pom with “pom” packaging Then each artifact becomes a maven module, each with its own pom Each Maven modules’ pom references the parent - dependencies and config will be inherited <parent> <groupId>org.justinjmoses.flexmojos-introduction</groupId> <artifactId>flexmojos-libraries</artifactId> <version>0.1-SNAPSHOT</version> </parent> One Maven module can depend on another - Maven will work out build order <dependency> <groupId>org.justinjmoses.flexmojos-introduction</groupId> <artifactId>flexmojos-libraries-library</artifactId> <version>${project.version}</version> <type>swc</type> </dependency>
  15. 15. GOTCHASAlways go back to first-principles - remove redundant code.Keep your build script thin.Try to reproduce outside your project - create an empty projectstructure with the bare minimum to reproduce.Check Flexmojos Google Groups.Found a bug? It’s open source. Hone your Java skills and contribute to agreat plugin.
  16. 16. WHAT ELSE CAN IT DO?Produce and optimise modular applicationsCreate RSLs from artifactsGenerate code coverage reportsOutput asdoc documentationCustomise the build based on different settings / build environments /sdksDeploy as bundled WAR with HTML wrapper
  17. 17. RESOURCESCode samples from today: github.com/justinjmosesFlexmojos docs: docs.sonatype.org/display/FLEXMOJOSFlexmojos goals and config: bitly.com/FM-4RC1-siteFlexmojos Google Groups: groups.google.com/forum/#!forum/flex-mojos @justinjmoses