guai
guai

Reputation: 805

How do I alias gradle task as if it were called with -x parameter?

I want instead of gradle cleanIdea idea -x compileJava -x compileTestJava call something like gradle ideaNoRecompile

Upvotes: 5

Views: 2142

Answers (2)

guai
guai

Reputation: 805

I've found another similar answer:

task ideaNoRecompile {
    finalizedBy allprojects*.tasks*.idea
    doFirst {
        def skipTasks = ['compileJava', 'compileMirah', 'processResources', 'classes', 'compileTestJava', 'compileTestMirah', 'processTestResources', 'testClasses', 'jar', 'mergeProperties', 'generateModuleManifest' ] as Set
        allprojects*.tasks*.each {
            if (skipTasks.contains(it.name))
                it.enabled = false
        }
    }
}

Upvotes: 0

Stanislav
Stanislav

Reputation: 28126

You can use TaskExecutionGraph to do it. First of all, you need to provide a custom task, named ideaNoRecompile, when during the configuration phase, you need to check, whether this graph contains ideaNoRecompile task (that means, that this task will be executed. And if this task should be executed, then you can use a closгre to skip all the tasks, you don't want to be executed. Something like this:

task ideaNoRecompile(dependsOn:idea) {
    gradle.taskGraph.whenReady { graph ->
        if (graph.hasTask(ideaNoRecompile)) {
            compileJava.enabled = false
            compileTestJava.enabled = false
        }
    }
}

Upvotes: 4

Related Questions