gpt4 book ai didi

android - 从模块运行 ktlint 的问题

转载 作者:太空狗 更新时间:2023-10-29 13:44:14 29 4
gpt4 key购买 nike

已更新 ktlint ,开始任务,一切正常。

这是我在 build.gradle 中的代码:

configurations {
ktlint
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
ktlint "com.pinterest:ktlint:0.34.2"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//...another dependencies
}

repositories {
jcenter()
}

configurations {
ktlint
}

task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
classpath = configurations.ktlint
main = "com.pinterest.ktlint.Main"
args "src/**/*.kt"
// to generate report in checkstyle format prepend following args:
// "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/ktlint.xml"
// see https://github.com/pinterest/ktlint#usage for more
}
check.dependsOn ktlint

task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
classpath = configurations.ktlint
main = "com.pinterest.ktlint.Main"
args "-F", "src/**/*.kt"
}

但是当我更改对我的模块的依赖时 custom_ktlint_rules

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
ktlint project(':custom_ktlint_rules')

然后运行任务,我得到这个错误:

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.

  • 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。使用 --scan 运行以获得完整的见解。

  • https://help.gradle.org 获得更多帮助

在 0 秒内构建失败

我的单独模块的 build.gradle 在这里:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'

compileOnly "com.pinterest:ktlint:$ktlintVersion"

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'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

最佳答案

使用最新版本 0.34.2 这个问题在最近的版本中已经解决。

更多详情请看here

使用this ktlint 库 "com.pinterest:ktlint:0.34.2"

试试这个:

ktlint project(':custom_ktlint_rules', configuration: 'default')

关于android - 从模块运行 ktlint 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57308689/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com