更新了克林特,启动了任务,一切都按其应有的方式工作。
这是我来自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')然后运行任务,我会得到以下错误:
失败:生成失败,出现异常。
构建在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"
}发布于 2019-08-08 18:18:29
所以,这就是我解决问题和运行ktlint的方式。
首先,我更新了根build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.41'
repositories {
google()
jcenter()
gradlePluginPortal()
}
dependencies {
classpath "org.jlleitschuh.gradle:ktlint-gradle:8.2.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
subprojects {
apply plugin: "org.jlleitschuh.gradle.ktlint" // Version should be inherited from parent
// Optionally configure plugin
ktlint {
debug = true
}
dependencies {
ktlintRuleset project(":custom_ktlint_rules")
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}在build.gradle中添加了下一个依赖项:
apply plugin: 'kotlin'
dependencies {
compileOnly("org.jetbrains.kotlin:kotlin-stdlib")
compileOnly("org.jetbrains.kotlin:kotlin-reflect")
compileOnly("org.jetbrains.kotlin:kotlin-script-runtime")
compileOnly("com.pinterest.ktlint:ktlint-core:0.34.2")
}https://stackoverflow.com/questions/57308689
复制相似问题