【问题标题】:Convert multiple ant mxmlc target into gradle using GradleFX plugin使用 GradleFX 插件将多个 ant mxmlc 目标转换为 gradle
【发布时间】:2018-07-10 19:57:24
【问题描述】:

我有一个使用 ANT 的复杂 java 和 flash 项目。我将项目转换为使用 gradle。有人可以帮助转换以下示例蚂蚁目标。

<target name="compile-flash">

    <mxmlc file="./flash/src/com/test/Some1.as" output="${build.dir}/flash/Some1.swf" debug="${flash.debug}" fork="true" maxmemory="512m">
        <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" />
        <load-config filename="./flash/conf/config1.xml" />
    </mxmlc>

    <mxmlc file="./flash/src/com/test/editor/Some2.as" output="${build.dir}/flash/Some2.swf" debug="${flash.debug}" fork="true" maxmemory="512m">
        <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" />
        <load-config filename="./flash/conf/config2.xml" />
    </mxmlc>

    <mxmlc file="${build.dir}/flashtest/flexunitapplication.mxml" output="${build.dir}/flashtest/FlexUnitApplication.swf" debug="true" fork="true">
        <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" />
        <load-config filename="flash/test/flexunit-config.xml" />
        <compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">
            <include name="libs" />
        </compiler.library-path>
        <compiler.library-path dir="${test.lib.dir}" append="true">
            <include name="swc"/>
        </compiler.library-path>
        <compiler.library-path dir="flash" append="true">
            <include name="lib/test" />
            <include name="lib" />
            <include name="bin" />
        </compiler.library-path>
        <compiler.headless-server>true</compiler.headless-server>
        <static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
        <compiler.verbose-stacktraces>true</compiler.verbose-stacktraces>
    </mxmlc>

    <compc output="${build.dir}/swc/client_api_release.swc" incremental="false" benchmark="false" static-link-runtime-shared-libraries="true" compiler.debug="false" debug="false" compiler.optimize="true" compiler.strict="true" compiler.verbose-stacktraces="false" target-player="11.1.0">
        <include-sources dir="${generated.actionscript.dir}" includes="**/*.as" />
        <compiler.include-libraries dir="${dependencies.lib.dir}/swc/" append="true">
            <include name="*.swc" />
            <exclude name="*debug*.swc" />
        </compiler.include-libraries>
        <external-library-path file="${FLEX_HOME}/frameworks/libs/framework.swc" append="true"/>
    </compc>
</target>

我知道这不符合惯例。但我不能改变结构,因为这是一个非常古老的项目。而且我不能为不同的 SWF 或 SWC 设置不同的模块。

谁能帮我使用 gradleFX gradle 插件实现同样的结果

提前致谢。

【问题讨论】:

    标签: flash gradle apache-flex ant gradlefx


    【解决方案1】:

    您可能希望使用 Gradle 的 UP-TO_DATE 检查,因此您需要为每个任务设置 TaskInputsTaskOutputs。它可能看起来像

    apply plugin: 'base'
    
    task compileFlash {}
    
    task mxmlc1 {
        inputs.file 'flash/src/com/test/Some1.as'
        inputs.file '${FLEX_HOME}/frameworks/flex-config.xml'
        inputs.file 'flash/conf/config1.xml'
        outputs.file "${build.dir}/flash/Some1.swf"
        doLast {
            ant.mxmlc(
                file:"flash/src/com/test/Some1.as", 
                output:"${build.dir}/flash/Some1.swf",
                debug="${flash.debug}",
                fork="true",
                maxmemory="512m"
            ) {
                'load-config'(filename:"${FLEX_HOME}/frameworks/flex-config.xml")
                'load-config'(filename:"./flash/conf/config1.xml")
            }
        }
    }
    
    task mxmlc2 { ... }
    task mxmlc3 { ... }
    
    compileFlash.dependsOn [mxmlc1, mxmlc2, mxmlc3, ...]
    
    compile.dependsOn compileFlash
    

    这可能会开始变得冗长,因此您可能会创建一个自定义任务,以便您可以执行类似的操作

    task mxmlc1(type:Mxmlx) {
        file = '"./flash/conf/config1.xml'
        loadConfig "${FLEX_HOME}/frameworks/flex-config.xml"
        loadConfig "/flash/conf/config1.xml"
        // etc etc
    }
    

    也许有人甚至为你编写了一个 gradle 插件来为你做这件事?

    【讨论】:

    • 是的,为此有一个插件 GradleFx (github.com/GradleFx/GradleFx)。但在他们的示例 (github.com/GradleFx/GradleFx-Examples) 中,他们建议为不同的 swf 使用不同的模块。这就是为什么我不知道如何在一个项目中拥有多个 Mxmlc。
    • 好吧,如果你不喜欢那个插件,编写你自己的 gradle 任务来包装 flex ant 任务会很简单。或者你可以像我演示的那样调用 ant inline
    猜你喜欢
    • 2017-01-24
    • 1970-01-01
    • 2018-09-06
    • 1970-01-01
    • 1970-01-01
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多