首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从模块运行ktlint时出现的问题

从模块运行ktlint时出现的问题
EN

Stack Overflow用户
提问于 2019-08-01 12:07:04
回答 2查看 8.7K关注 0票数 6

更新了克林特,启动了任务,一切都按其应有的方式工作。

这是我来自build.gradle的代码

代码语言:javascript
复制
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

代码语言:javascript
复制
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    ktlint project(':custom_ktlint_rules')

然后运行任务,我会得到以下错误:

失败:生成失败,出现异常。

  • 出了什么问题:无法确定任务的依赖性':app:ktlint‘。 无法解决配置的所有任务依赖关系“:app:ktlint”。无法解决项目:custom_ktlint_rules。required by: project :app不能在项目:custom_ktlint_rules的以下变体之间进行选择:- debugRuntimeElements - releaseRuntimeElements --所有这些变量都匹配使用者属性:-变量“调试器运行时元素”:- Found 'debug‘,但不是必需的。-找到了com.android.build.api.attributes.VariantAttr‘调试’,但不是必需的。-找到了com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Apk‘,但不是必需的。-找到了org.gradle.usage‘java-运行时’,但不是必需的。-找到了org.jetbrains.kotlin.platform.type 'androidJvm‘但不是必需的。-变体'releaseRuntimeElements':-找到了com.android.build.api.attributes.BuildTypeAttr 'release‘,但不是必需的。-找到了com.android.build.api.attributes.VariantAttr‘释放’,但不是必需的。-找到了com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Apk‘,但不是必需的。-找到了org.gradle.usage‘java-运行时’,但不是必需的。-找到了org.jetbrains.kotlin.platform.type 'androidJvm‘但不是必需的。
  • 尝试:使用--stacktrace选项运行以获得堆栈跟踪。使用--info或-调试选项运行以获得更多日志输出。用扫描来获得完整的洞察力。
  • https://help.gradle.org获得更多帮助

构建在0中失败

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

代码语言:javascript
复制
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"
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-08-08 18:18:29

所以,这就是我解决问题和运行ktlint的方式。

首先,我更新了根build.gradle

代码语言:javascript
复制
// 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中添加了下一个依赖项:

代码语言:javascript
复制
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")
}
票数 1
EN

Stack Overflow用户

发布于 2019-08-05 13:41:06

使用最新版本的0.34.2,这个问题在最近的版本中得到了解决。

有关更多细节,请参见这里

使用库进行ktlint "com.pinterest:ktlint:0.34.2"

试试这个:

代码语言:javascript
复制
ktlint project(':custom_ktlint_rules', configuration: 'default')
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57308689

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档