1

Here is what I do in general build.gradle without gradlew.

task play(type: Exec) {
    commandLine 'sh', './test_work.sh'
}

build.dependsOn play 

This is the first task gets executed when I run gradle build.

I want to do the same thing when I run gradle assembleDebug. Here is what I am doing right now:

android {
    compileSdkVersion A
    buildToolsVersion "X.Y.Z"

    defaultConfig {
        applicationId "helloWorld"
        minSdkVersion X
        targetSdkVersion Y
    }
    buildTypes {
        applicationVariants.all { variant ->
            variant.outputs.each { output ->
                output.outputFile = file("$project.buildDir/outputs/helloWorld.apk")
        }
    }
    debug {
        minifyEnabled false
    }

    release {
        minifyEnabled true
    }
}

    task test(type: Exec) << {
    println "Hi"
    commandLine 'sh', './new_test.sh'
    }
}

repositories {
    ....
    } 

dependencies {
    ....
    }

}

assemble.dependsOn deployGitHooks

Somehow the task test is not getting executed.

Can anybody please help.

Thanks...

Jason
  • 2,246
  • 6
  • 34
  • 53
  • Why would it execute? No task depends on it. So unless you execute gradle test, it won't execute. Also, you're configuring the task in the execution phase. – JB Nizet Aug 02 '15 at 18:46
  • I added `assemble.dependsOn deployGitHooks` all I want to do is let assembleDebug depend on it.How can I do that ? I mean all I want to execute new_test.sh as the first task, when I run gradle assembleDebug. – Jason Aug 03 '15 at 06:26
  • Then name your task `deployGitHooks`. You've named it `test`. And remove the `<<`. – JB Nizet Aug 03 '15 at 06:30
  • So, if you try what you mentioned it executes the task and prints "Hi". However it does not execute the script new_test.sh. – Jason Aug 03 '15 at 22:01
  • Here is how I got it to work: `task deployGitHooks(type: Exec) { def script = "bash git_hooks.sh".execute() script.in.eachLine {line -> println line} }` [run-task-before-compilation-using-android-gradle-plugin](http://stackoverflow.com/questions/16853130/run-task-before-compilation-using-android-gradle-plugin) – Jason Aug 03 '15 at 22:48

0 Answers0