2013-08-31 53 views
2

我有這個gradle構建文件。如何在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文件

能有人幫幫我嗎?

回答

0

我是一個總的聖女到搖籃,所以我只能爲你提供的猜測:

  1. 統一聲明依賴的方式

    taskB.dependsOn tasksA

  2. 強制任務的順序(附加依賴)

    taskB.mustRunAfter(taskA)

  3. 添加日誌,查看任務是否被執行VS任務不符合您的期望。

添加依賴於一個任務/訂貨任務

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

請向我們提供的解決方案,一旦你得到它!