【发布时间】:2019-08-01 12:07:04
【问题描述】:
更新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:构建失败并出现异常。
出了什么问题:无法确定任务 ':app:ktlint' 的依赖关系。
无法解析配置“:app:ktlint”的所有任务依赖项。 无法解析项目:custom_ktlint_rules。 要求: 项目:应用程序 无法在以下项目变体中进行选择:custom_ktlint_rules: - 调试运行时元素 - 发布运行时元素 它们都符合消费者属性: - 变体'debugRuntimeElements': - 找到 com.android.build.api.attributes.BuildTypeAttr 'debug' 但不是必需的。 - 找到 com.android.build.api.attributes.VariantAttr 'debug' 但不是必需的。 - 找到 com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Apk' 但是 不是必需的。 - 找到 org.gradle.usage 'java-runtime' 但不是必需的。 - 找到 org.jetbrains.kotlin.platform.type 'androidJvm' 但不是必需的。 - 变体“releaseRuntimeElements”: - 找到 com.android.build.api.attributes.BuildTypeAttr 'release' 但不是必需的。 - 找到 com.android.build.api.attributes.VariantAttr 'release' 但不是必需的。 - 找到 com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Apk' 但是 不是必需的。 - 找到 org.gradle.usage 'java-runtime' 但不是必需的。 - 找到 org.jetbrains.kotlin.platform.type 'androidJvm' 但不是必需的。
尝试:使用 --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"
}
【问题讨论】:
-
您使用的是最新版本吗?最新版本解决了这个问题
-
@GOVINDDIXIT ext.ktlintVersion = '0.29.0'
-
试试这个版本'0.34.2'
-
我已经添加了一个答案,希望它能解决这个问题。
标签: android android-gradle-plugin