Ktlint: Kotlin DSL check the task issue

Created on 22 May 2019  路  6Comments  路  Source: pinterest/ktlint

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.

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-base plugin for the check task to be added to your project.

plugins {
    `lifecycle-base`
}

All 6 comments

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:

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`
}

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jbarr21 picture jbarr21  路  5Comments

vanniktech picture vanniktech  路  5Comments

DanteAndroid picture DanteAndroid  路  3Comments

xenomachina picture xenomachina  路  5Comments

pkubowicz picture pkubowicz  路  4Comments