Does the latest GradleFX support modules?

saifeng.ji's Avatar

saifeng.ji

18 Jul, 2013 08:01 PM

Hi,
     The GradleFX is an great plugin for compiling Flex application with Gradle. I am also successful to test it with one simple Flex project. Now I am trying to implement the same to my real flex project, which is big and complicated, at least there're several modules ( swf ) need be compiled.
     I googled the modules feature of GradleFX. Found some old discussion threads without conclusions and I couldn't find any related information in gradleFX website, either.

     Can anyone tell me does it support modules now? If not, what will be the alternative way to do moudle compile in Gradle? Invoke Ant target?

Thanks in advance.

  1. Support Staff 1 Posted by Yennick Trevels on 18 Jul, 2013 08:47 PM

    Yennick Trevels's Avatar

    Hi,

    GradleFx doesn't officially support modules yet.
    The furthest we got with it is discussed in this thread https://github.com/GradleFx/GradleFx/issues/46. In that thread you'll find a link to a sample project I made with a module (which didn't fully work, but Patrick Mowrer got it to work).

    If that isn't working then I'm afraid you'll have to write some custom code for it (of which invoking the Ant target could be an option).

  2. 2 Posted by saifeng.ji on 25 Jul, 2013 10:11 PM

    saifeng.ji's Avatar

    Hi, my current solution is to invoke ant task in gradle, attache the codes:

    And my current problem is that how could I use dependencies management for swc files in ant task?
    in ant mxmlc task, we need define "library-path" with dir and swc names, but if the swcs are from maven cache, which is actually seperately located in different dirs.
    And it's also difficult to pass all file paths and names from gradle to ant.

    there's one thought whis is that I could copy all swcs from maven cache into internal flex_libs folder, which is easily for me to define it in ant task.

    Any idea about it? how the gradleFX actually handle dependencies for flex swcs?

    And one further question is that my project is actually combined one ( Flex + Java ), is it possible to do all in one gradle script instead of seperate theminto different sub-projects?

    Attached codes:

    dependencies {
        theme files("${flexHome}/frameworks/themes/Halo/halo.swc")

        external files("flex_libs/CWMModel.swc")
        external files("flex_libs/Fisheye.swc")
        external files("flex_libs/WKSTFxFrameWork.swc")

        //antFlexCompile files("${flexHome}/frameworks/themes/Halo/halo.swc")
        antFlexCompile 'com.jpmorgan.empire:flextasks:4.1'
        antFlexCompile files("flex_libs/CWMModel.swc")
        antFlexCompile files("flex_libs/Fisheye.swc")
        antFlexCompile files("flex_libs/WKSTFxFrameWork.swc")
    }

    // Ant Section
    ant.buildDir = buildDir
    ant.baseDir = projectDir
    ant.FLEX_HOME = flexHome

    task initAnt {
        ant.taskdef(name: 'compileFlexModule', classname: 'flex.ant.MxmlcTask', classpath: configurations.antFlexCompile.asPath)
    }

    tasks.addRule("Pattern: compileFlexModule_module") { def taskName ->
        if (taskName.startsWith("compileFlexModule_")) {
            task(taskName) << {
                moduleName = taskName - 'compileFlexModule_'

                ant.module_mxml = getProperty('flex_modules_' + moduleName + '_mxml')
                ant.module_swf = getProperty('flex_modules_' + moduleName + '_swf')

                configurations.antFlexCompile.files.each { file ->
                    println "$file.name -> $file.path"
                }

                ant.compileFlexModule ( file: '${baseDir}/flex_src/${module_mxml}',
                        debug: 'true',
                        output: '${buildDir}/${module_swf}',
                        "keep-generated-actionscript": 'false',
                        "link-report": '${baseDir}/MyReport.xml',
                        warnings: 'false',
                        incremental: 'false') {
                    theme(dir: '${FLEX_HOME}/frameworks/themes/Halo') {
                        include(name: 'halo.swc')
                    }

                    "load-config"(filename: '${FLEX_HOME}/frameworks/flex-config.xml')
                    "source-path"("path-element": 'flex_src')
                    "library-path"(dir: 'flex_libs', append: 'true') {
                        include(name: '*.swc')
                    }
                }
            }
        }
    }

    task buildAllFlexModules {
        dependsOn initAnt, compileFlexModule_accounts
    }

  3. Support Staff 3 Posted by Yennick Trevels on 26 Jul, 2013 07:28 AM

    Yennick Trevels's Avatar

    Here are some code snippets which show you how we add those dependencies as arguments to an Ant task:

    /********* Code which is called to add libraries to the compiler arguments list *******/
    addLibraries(project.configurations.internal, "-include-libraries")
    addLibraries(project.configurations.external, "-external-library-path")
    addLibraries(project.configurations.merged, "-library-path") 
    addLibraries(project.configurations.theme, "-theme") 
    
    /********* Code which adds those libraries to a list of compiler arguments **********/
    List arguments = []
    
    def addLibraries(Configuration configuration, String compilerOption) {
        Set<File> libraryFiles = configuration.files
    
        //only add swc dependencies, no use in adding pom dependencies
        Collection<File> files = libraryFiles.findAll {
            it.name.endsWith(FlexType.swc.toString()) || it.isDirectory()
        }
    
        Collection paths = files.collect { it.path }
        addAll compilerOption, paths
    }
    
    public void addAll(String compilerOption) Collection<String> values) {
            values.each { add compilerOption) it }
    }
    
    public void add(String compilerOption) String value) {
            arguments.add "$compilerOption) +=$value"
    }
    
    
    /********** Code which uses the compiler arguments in an Ant java task **********/
    ant.java(
        jar: "$flexConvention.flexHome/lib/${antTask}.jar",
        dir: "$flexConvention.flexHome/frameworks",
        fork: true,
        resultproperty: antResultProperty,
        outputproperty: antOutputProperty
    ) {
    
        arguments.each {
            arg(value: it)
        }
    }
    

    Hope this helps you a bit. You can find more of this code in https://github.com/GradleFx/GradleFx/blob/develop/src/main/groovy/o...

    Regarding the Flex + Java combo. I'd highly recommend to keep them separate projects, because you'll probably run into problems otherwise. Plus it's generally a best practice in Gradle to separate projects.

  4. 4 Posted by saifeng.ji on 26 Jul, 2013 06:38 PM

    saifeng.ji's Avatar

    Hi,

    Thanks for your continuous support. And I did learn a lot from your source code.
    Attached my simple codes, at least it could solve my issue.

    task buildAllFlexModules(dependsOn: initAnt, type: AntFlexTask) {
        flexLibs = configurations.flexCompile;

        compileFlexModule("...", "...")
    }

    class AntFlexTask extends DefaultTask {
        def String greeting = "Hello from AntFlexTask"
        def FileCollection flexLibs

        @TaskAction
        def antFlexTask() {
            println '******************* [Exit AntFlexTask] *******************'
        }

        def compileFlexModule(module, swf) {
            println '>>> [AntFlexTask] start compiling flex module: ' + module

            ant.compileFlex (
                    file: '${baseDir}/flex_src/' + module,
                    debug: flex_debug,
                    output: '${buildDir}/' + swf,
                    "keep-generated-actionscript": 'false',
                    "link-report": '${baseDir}/MyReport.xml',
                    warnings: 'false',
                    incremental: 'false')
            {
                theme(dir: '${FLEX_HOME}/frameworks/themes/Halo') {
                    include(name: 'halo.swc')
                }

                "load-config"(filename: '${FLEX_HOME}/frameworks/flex-config.xml')
                "source-path"("path-element": 'flex_src')

                flexLibs.each {File file ->
                    "include-libraries"(dir: file.parent, append: 'true') {
                        include(name: file.name)
                    }
                }
            }
        }
    }

    Thanks.

  5. Support Staff 5 Posted by Yennick Trevels on 26 Jul, 2013 08:57 PM

    Yennick Trevels's Avatar

    Cool. Glad I could help you :)

  6. Yennick Trevels closed this discussion on 26 Jul, 2013 08:57 PM.

  7. saifeng.ji re-opened this discussion on 29 Jul, 2013 02:15 PM

  8. 6 Posted by saifeng.ji on 29 Jul, 2013 02:15 PM

    saifeng.ji's Avatar

    opps...

    Can you help to edit my previous post by removing the method codes

    task buildAllFlexModules(dependsOn: initAnt, type: AntFlexTask) {
        flexLibs = configurations.flexCompile;

        compileFlexModule("...", "...")
    }

    Thanks in advance.

  9. Support Staff 7 Posted by Yennick Trevels on 29 Jul, 2013 03:04 PM

    Yennick Trevels's Avatar

    Done ;)

  10. 8 Posted by XRumerTest on 26 Sep, 2014 06:54 PM

    XRumerTest's Avatar

    Hello. And Bye.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

07 May, 2023 04:17 PM
28 Apr, 2023 11:22 PM
23 Apr, 2023 09:43 AM
03 Nov, 2022 01:22 AM
29 Jun, 2022 05:39 PM

 

04 Aug, 2021 12:50 PM
15 Apr, 2021 06:10 PM
15 Jan, 2021 06:56 PM
09 Mar, 2020 11:11 PM
09 Mar, 2020 11:09 PM
17 Apr, 2019 02:51 PM