Gradle custom task which runs multiple tasks

前端 未结 8 901
不知归路
不知归路 2020-12-07 17:16

I wanna run multiple gradle tasks as one. So instead of

./gradlew clean build publish

I want to have a custom task

./gradl         


        
相关标签:
8条回答
  • 2020-12-07 18:03

    Here is how I did it, with Kotlin scripting, using both dependsOn and mustRunAfter. Here is an example of running two tasks, one (custom registered "importUnicodeFiles" task) that is in "this" project and one (predefined "run" task) that is in a sibling project named ":unicode":

    tasks.register("rebuildUnicodeFiles") {
        description = "Force the rebuild of the `./src/main/resources/text` data"
        val make = project(":unicode").tasks["run"]
        val copy = tasks["importUnicodeFiles"]
        dependsOn(make)
        dependsOn(copy)
        copy.mustRunAfter(make)
    }
    
    0 讨论(0)
  • 2020-12-07 18:06

    Try below way to make cleanBuildPublish depend on other tasks

    build.gradle

    task clean{
        println "lets clean"
    }
    
    task build {
        println "lets build"
    }
    
    task publish {
        println "lets publish"
    }
    
    task cleanBuildPublish{
        println 'lets do all'
    }
    
    
    cleanBuildPublish.dependsOn clean
    cleanBuildPublish.dependsOn build
    cleanBuildPublish.dependsOn publish
    

    Output

    $ gradle cleanBuildPublish
    lets clean
    lets build
    lets publish
    lets do all
    :build UP-TO-DATE
    :clean UP-TO-DATE
    :publish UP-TO-DATE
    :cleanBuildPublish UP-TO-DATE
    
    BUILD SUCCESSFUL
    
    Total time: 2.738 secs
    

    check https://docs.gradle.org/current/userguide/more_about_tasks.html#addDependencyUsingTask for more details

    0 讨论(0)
提交回复
热议问题