Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run gradle task from condition

Tags:

gradle

I am relatively new to gradle so please be patient with me. My build.gradle:

def releaseBol = false

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    lintOptions {
        abortOnError false
    }

    ...
    if (project.hasProperty('RELEASE') && project.ext.RELEASE == '1')
        releaseBol = true


    if (releaseBol)
    {
       ..
       //some code
       ..

    }

}

...

task runScheduleReader()  {
    javaexec {
        println 'here1'
        main="-jar";
        args = [
                "../Generator.jar"

        ]
    }
}

What I wish to is to run runScheduleReader if releaseBol is set to true, but I get an error when just moving it there, how can I do this?

like image 427
Dim Avatar asked Jul 01 '26 01:07

Dim


1 Answers

Try:

task runScheduleReader()  {
    enabled = releaseBol
    doLast {
       javaexec {
          println 'here1'
          main="-jar";
          args = [
                "../Generator.jar"
          ]
       }
    }
}

Please have a look at enabling and disabling tasks. The second problem is that you added the logic at configuration time so it will be executed every time the script is evaluated. You need to add an action with doLast.

like image 115
Opal Avatar answered Jul 05 '26 03:07

Opal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!