How to execute the gradle alias as if it were called with the -x option?

I want instead of gradle cleanIdea idea -x compileJava -x compileTestJava calling something likegradle ideaNoRecompile

+4
source share
2 answers

You can use TaskExecutionGraphfor this. First of all, you need to provide a custom task with a name ideaNoRecompile, when at the configuration stage you need to check whether this schedule contains a ideaNoRecompiletask (this means that this task will be completed. And if this task needs to be completed, then you can use closure to skip all the tasks you don’t want to do, something like this:

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

I 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
        }
    }
}
0
source

Source: https://habr.com/ru/post/1625107/


All Articles