0

我正在将我们的 flex 应用程序迁移到使用 gradle 构建。到目前为止,一切进展顺利,除了单元测试。

build.gradle

description='Parent project for flex applications'

buildscript {
    repositories {
        mavenCentral()
        mavenLocal()
    }

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

allprojects {
    group='com.mycompany.flex'
    version='0.0.1-SNAPSHOT'

    repositories {
        mavenCentral()
        mavenLocal()
    }
}

subprojects {
    apply plugin: 'gradlefx'

    dependencies {
        flexSDK group: 'org.apache', name: 'apache-flex-sdk', version: '4.1.0A', ext: 'zip' 

        //unit test libraries
        test group: 'org.hamcrest', name: 'hamcrest-as3-flex', version: '1.1.3', ext: 'swc'

        test group: 'org.flexunit', name: 'flexunit-tasks', version: '4.1.0-8', ext: 'jar'
        test group: 'org.flexunit', name: 'flexunit-flex', version: '4.1.0-8', ext: 'swc'
        test group: 'org.flexunit', name: 'flexunit-cilistener', version: '4.1.0-8', ext: 'swc'     
    }


    flexUnit { 
        command="C:/Windows/System32/Macromed/Flash/flashplayer_11_sa_debug.exe"
    }
}

有问题的项目build.gradle

description='module_MyModule'
type = 'swf'

dependencies {
    rsl project(':library_common')

    external group: 'flexlib', name: 'flexlib', version: '2.5', ext: 'swc'

    merged group: 'com.esri.ags', name: 'agslib', version: '2.5-2011-11-30', ext: 'swc'
    merged group: 'org.robotlegs', name: 'robotlegs-framework', version: '1.5.2', ext: 'swc'
    merged group: 'org.alivepdf', name: 'alivepdf', version: '0.1.5RCfeb2010', ext: 'swc'
}

编译没有问题,gradle test结果如下:

:module_MyModule:test
[ant:flexunit] Compiling test classes: [com.mycompany.MyModelTest]
[ant:null] Loading configuration file C:\Users\PGreen\.gradle\gradleFx\sdks\56bb8970d35ada5a72c3596118157aa694a7e83e\frameworks\flex-config.xml
:module_MyModule:test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':module_MyModule:test'.
> Compilation failed:
C:\development\flexworkspaces\gradle\module_MyModule\src\main\actionscript\com\mycompany\MyModel.as(11): col: 22 Error: The definition of base class BaseModel was not found.

      public class MyModel extends BaseModel
                                   ^


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 14.006 secs

基类BaseModel在项目 ':library_common' 中定义。如果我将配置从 更改rslmerged,一切正常。所以这个问题似乎与 Flash 播放器在运行时尝试加载它时不知道在哪里寻找 ':library_common' 有关。我该如何指定?在我的搜索中,我发现使用 flexmojos 插件的 maven 存在类似问题,但总体上没有解决方案。

4

1 回答 1

0

此时,单元测试应用程序的编译被委派给 FlexUnit 附带的 ANT 任务(我假设使用 FlexMojos 进行单元测试的工作方式类似)。不幸的是,这项任务似乎不能很好地处理一些情况。

我们还有其他具有相同根本原因的问题;例如“运行 FlexUnit 测试时无法保留元数据”
我们在管道中有一个解决方案,但它需要我们重写test任务,以便 GradleFx 编译测试应用程序并将生成的 swf 传递给 FlexUnit,而不是让 FlexUnit 进行编译。正如您可能已经猜到的那样,这不会在一夜之间得到解决。

与此同时,我只能为您提供一个我尚未测试过的建议:也许可以通过将其添加到您的构建脚本中,将您的 RSL 置于test范围之上:rsl

test project(':library_common')
于 2013-02-16T14:40:44.883 回答