2

我有这个 gradle 构建文件。

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
        classpath 'com.eriwen:gradle-css-plugin:1.2.1'
        classpath 'com.eriwen:gradle-js-plugin:1.5.1'
    }
}

apply plugin: 'android'
apply plugin: 'js'
apply plugin: 'css'

dependencies {
    compile files('libs/android-support-v4.jar')
    compile files('libs/cordova-2.7.0.jar')
    compile files('libs/libGoogleAnalyticsV2.jar')
}

task MinifyJSForRelease {

tasks.add(name:"copyTask2", type:Copy){
    from 'assets/'
    into 'build/minifiedassets/assets'
}
it.dependsOn copyTask2
def tester = fileTree(dir:"build/minifiedassets/assets", include:"**/*.js");
println tester
tester.eachWithIndex {File file, idx ->
    tasks.add(name: "makeMinifyJS${idx}", type: com.eriwen.gradle.js.tasks.MinifyJsTask) {
        source = file
        dest = "${file.path}"
        closure {

            compilerOptions.languageIn = "ECMASCRIPT5"
        }

    }
}

it.dependsOn tasks.matching { Task task -> task.name.startsWith("makeMinifyJS")}
}

build.dependsOn MinifyJSForRelease

android {
compileSdkVersion 17
buildToolsVersion "17"

signingConfigs {
    release {
        storeFile file('keystores/mobilecoe_android.keystore')
        storePassword "mobilecoe"
        keyAlias "MobileCoE"
        keyPassword "mobilecoe"
    }
}

defaultConfig {
    minSdkVersion 10
    targetSdkVersion 16
}
buildTypes {
    debug {

        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']
                aidl.srcDirs = ['src']
                renderscript.srcDirs = ['src']
                res.srcDirs = ['res']
                assets.srcDirs = ['assets']
            }

            instrumentTest.setRoot('tests')
        }
    }

    release {

        signingConfig signingConfigs.release
        zipAlign true
        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']
                aidl.srcDirs = ['src']
                renderscript.srcDirs = ['src']
                res.srcDirs = ['res']
                assets.srcDirs = ['build/minifiedassets/assets']
            }

            instrumentTest.setRoot('tests')
        }
    }
}
}

我想像第一件事一样运行任务MinifyJSForRelease,将资产文件夹复制到我想要的位置,然后在完成后我想缩小 JS 文件。现在,当我运行任务时,它会复制文件夹但没有到达末尾,下一个函数说它没有什么可以缩小的,但是如果我第二次运行任务(当文件夹已被复制时),它会阻止它并执行所有操作。

我做错了什么?我需要:

  1. 复制文件夹
  2. 获取文件夹并缩小其 js 文件

有人可以帮我吗?

4

1 回答 1

0

我完全是 Gradle 的处女座,所以我只能为您提供有根据的猜测:

  1. 统一声明依赖的方式

    taskB.dependsOn 任务A

  2. 强制任务的顺序(添加依赖项)

    taskB.mustRunAfter(taskA)

  3. 添加日志,以查看任务是否已执行 VS 任务没有按照您的预期执行。

将依赖项添加到任务/排序任务

http://www.gradle.org/docs/current/userguide/more_about_tasks.html

请在您得到解决方案后为我们提供解决方案!

于 2014-01-03T11:57:52.140 回答