Tim
Tim

Reputation: 2066

Control the gradle task execute order

I have a strange problem about gradle task recently.

Assume I have a simple gradle config as follows

apply plugin: "java"
apply plugin: "maven"

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "com.diffplug.gradle.spotless:spotless:2.0.0"
    }
}

apply plugin: "com.diffplug.gradle.spotless"


spotless {
    java {
        eclipseFormatFile 'format.xml'  // XML file dumped out by the Eclipse formatter
    }
}

spotlessJavaCheck.dependsOn(processResources)

version = '1.0-SNAPSHOT'

I just want to set the depends on relationship for the spotless check. After I run a build, the error looks like this

> Could not find property 'spotlessJavaCheck' on root project 'gradle-helloworld'.

I have done something similar with other plugins, it works well, but not for this spotless plugin.

Br,

Tim

Upvotes: 2

Views: 714

Answers (1)

Crazyjavahacking
Crazyjavahacking

Reputation: 9717

Spotless Gradle plugin does magic at configuration time.

You need to set the dependency after evaluation time, once the magic is done:

afterEvaluate {
    tasks['spotlessJavaCheck'].dependsOn processResources
}

Upvotes: 2

Related Questions