Monday, 5 August 2019

Problems running ktlint

Wrote custom rule(took example from here). Added all into a module, try to run ktlint from main project, get the following error:

FAILURE: Build failed with an exception.

  • What went wrong:

Could not determine the dependencies of task ':app:ktlint'. Could not resolve all task dependencies for configuration ':app:ktlint'. Could not resolve project :custom_ktlint_rules. Required by: project :app Cannot choose between the following variants of project :custom_ktlint_rules: - debugRuntimeElements - releaseRuntimeElements All of them match the consumer attributes: - Variant 'debugRuntimeElements': - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required. - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required. - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Apk' but wasn't required. - Found org.gradle.usage 'java-runtime' but wasn't required. - Found org.jetbrains.kotlin.platform.type 'androidJvm' but wasn't required. - Variant 'releaseRuntimeElements': - Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required. - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required. - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Apk' but wasn't required. - Found org.gradle.usage 'java-runtime' but wasn't required. - Found org.jetbrains.kotlin.platform.type 'androidJvm' but wasn't required.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 0s

Have next code in my main project:

configurations {
    ktlint
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    ktlint "com.github.shyiko:ktlint:$ktlintVersion"
    ktlint project(":custom_ktlint_rules")
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.google.firebase:firebase-auth:16.1.0'
    implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
    implementation 'com.google.firebase:firebase-messaging:17.4.0'
    implementation 'com.google.firebase:firebase-database:16.0.6'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

def outputDir = "${project.buildDir}/reports/ktlint/"

task ktlint(type: JavaExec, group: "verification", description: "Runs ktlint.") {
    main = "com.github.shyiko.ktlint.Main"
    classpath = configurations.ktlint
    args = [
            "--reporter=plain",
            "--reporter=checkstyle,output=${outputDir}ktlint-checkstyle-report.xml",
            "src/**/*.kt"
    ]

    // To make this Gradle task incremental - https://medium.com/@vanniktech/making-your-gradle-tasks-incremental-7f26e4ef09c3
    inputs.files(
            fileTree(dir: "src", include: "**/*.kt"),
            fileTree(dir: ".", include: "**/.editorconfig")
    )
    outputs.dir(outputDir)
}

task ktlintFormat(type: JavaExec, group: "formatting") {
    description = "Runs ktlint and autoformats your code."
    main = "com.github.shyiko.ktlint.Main"
    classpath = configurations.ktlint
    args = [
            "-F",
            "src/**/*.kt"
    ]

    // To make this Gradle task incremental - https://medium.com/@vanniktech/making-your-gradle-tasks-incremental-7f26e4ef09c3
    inputs.files(
            fileTree(dir: "src", include: "**/*.kt"),
            fileTree(dir: ".", include: "**/.editorconfig")
    )
    outputs.upToDateWhen { true }
}

apply plugin: 'com.google.gms.google-services'



from Problems running ktlint

No comments:

Post a Comment