Hi all,
I am converting my gradle files to kotlin-dsl. I have a child gradle file called ktlint.gradle.kts. In addition, I configure ktlint there as following.
val ktlint: Configuration by configurations.creating
repositories {
jcenter()
}
dependencies {
ktlint(Deps.ktlint)
}
tasks.register<JavaExec>("ktlint") {
group = "verification"
description = "Check Kotlin code style."
classpath = ktlint
main = "com.github.shyiko.ktlint.Main"
args("--android", "src/**/*.kt")
}
tasks.named("check") {
dependsOn(ktlint)
}
tasks.register<JavaExec>("ktlintFormat") {
group = "formatting"
description = "Fix Kotlin code style deviations."
classpath = ktlint
main = "com.github.shyiko.ktlint.Main"
args("--android", "-F", "src/**/*.kt")
}
Then I apply this configuration for all modules inside build.gradle.kts
allprojects {
apply(from = "$rootDir/ktlint.gradle.kts")
}
When I try to compile the project I am getting the error below: -- this error is related to the check task which is placed in ktlint.gradle.kts
FAILURE: Build failed with an exception.
* Where:
Script '../MultiScrollView/ktlint.gradle.kts' line: 19
* What went wrong:
Task with name 'check' not found in root project 'MultiScrollView'.
Can you please help me overcome this error. Thanks in advance.
Consider using the following plugins that will give you this functionality for free:
As to more specifically your problem, you need to add the lifecycle-base plugin for the check task to be added to your project.
plugins {
`lifecycle-base`
}
Hi @JLLeitschuh ,
Thanks for your answer. I will definitely take a look at these cool ones.
Personally I use Kotlinter: https://github.com/jeremymailen/kotlinter-gradle because I had issues using Spotless (didn't support newer ktlint and Kotlin compiler versions)
Consider using the following plugins that will give you this functionality for free:
- https://github.com/diffplug/spotless/tree/master/plugin-gradle#applying-ktlint-to-kotlin-files
- https://github.com/JLLeitschuh/ktlint-gradle#tasks-added
As to more specifically your problem, you need to add the
lifecycle-baseplugin for thechecktask to be added to your project.plugins { `lifecycle-base` }
Could you clarify why adding this plugin fixes it?
@ShaunPlummer The lifecycle-base plugin in Gradle is the one that adds the check, build, ect... tasks to the task graph.
Closing due to inactivity. Feel free to reopen if the issue is still there
Most helpful comment
Consider using the following plugins that will give you this functionality for free:
As to more specifically your problem, you need to add the
lifecycle-baseplugin for thechecktask to be added to your project.