I have a Gradle project with several submodules. In my project there is a spotless task configured. Now I want to make a compileJava
task dependent on spotlessApply
task. I try it in this way:
subprojects {
apply plugin: 'java'
apply plugin: 'com.diffplug.gradle.spotless'
spotless {
java {
target 'src/**/*.java'
licenseHeaderFile "$rootDir/buildSrc/CopyrightHeader.java"
importOrder(['java', 'javax', 'org', 'com'])
eclipseFormatFile "$rootDir/buildSrc/formatter.xml"
}
format 'misc', {
target 'src/**/*.md', 'src/**/*.xml', 'src/**/*.xsd', 'src/**/*.xsl'
indentWithSpaces()
trimTrailingWhitespace()
endWithNewline()
}
}
compileJava.dependsOn spotlessApply
}
But it produces an error:
Could not get unknown property 'spotlessApply' for project (...) of type org.gradle.api.Project.
I also tried something like this:
compileJava.dependsOn project.tasks.findByName('spotlessApply')
But it doesn't work.
An IntelliJ plugin to allow running the spotless gradle task from within the IDE on the current file selected in the editor. You may find the spotless action via Code > Reformat Code with Spotless.
dependsOn(jar) means that if you run assemble , then the jar task must be executed before. the task transitive dependencies, in which case we're not talking about tasks, but "publications". For example, when you need to compile project A , you need on classpath project B , which implies running some tasks of B .
compileJava — JavaCompile. Depends on: All tasks which contribute to the compilation classpath, including jar tasks from projects that are on the classpath via project dependencies. Compiles production Java source files using the JDK compiler.
Running Spotless Spotless can be ran using ./gradlew spotlessApply which will apply all formatting options. You can also specify a specific task by just adding the name of formatter. An example is ./gradlew spotlessmiscApply . Spotless can also be used as a CI check.
The Spotless plugin creates its tasks in an project.afterEvaluate
block to allow you to configure the extension before it creates the task(s) - see here
To solve this, simply depend on the task's name (i.e. as a string) instead and Gradle will resolve the task when its needed.
compileJava.dependsOn 'spotlessApply'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With