gradle - 将 Kotlin 的 detekt 版本定义为额外属性(ext)

标签 gradle kotlin detekt

Groovy 允许在 ext 中为项目定义额外的属性。 .

我想在 groovy 的额外属性中定义 Detekt 的版本。 Detekt 是 Kotlin 语言的静态代码分析工具。

但是,当我按照以下方式进行操作时:

buildscript {
    // testing, code-style, CI-tools
    ext.detect_code_analysis = '1.0.0.RC6-3' //change to 1.0.0 when available

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:$gradle_version"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
plugins {
    id "io.gitlab.arturbosch.detekt" version "$detect_code_analysis"
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

detekt {
    version = "$detect_code_analysis"
    profile("main") {
        input = "$projectDir/app/src/main/java"
        config = "$projectDir/detekt-config.yml"
        filters = ".*test.*,.*/resources/.*,.*/tmp/.*"
    }
}

它提示:
Error:(17, 0) startup failed:
        build file '/Users[...]build.gradle': 17: argument list must be exactly 1 literal non empty string

See https://docs.gradle.org/4.1/userguide/plugins.html#sec:plugins_block for information on the plugins {} block

@ line 17, column 5.
        id "io.gitlab.arturbosch.detekt" version "$detect_code_analysis"
^

1 error

最佳答案

“新风格”Gradle 插件定义(不包括对 buildscript block 的完全依赖)不允许版本中的变量。

有关更多信息,请参阅错误消息中提到的文档部分。有一个小节“插件 dsl 的限制”解释了一切。

如果您想继续使用可变版本字符串,您需要使用 apply plugin: “xxx” 返回到“旧方式”。句法。

关于gradle - 将 Kotlin 的 detekt 版本定义为额外属性(ext),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49235194/

相关文章:

android - Windows 10的React-Native Android问题

android - 如何使用/Android Studio/Kotlin 访问 Firebase Firestore 中的数组字段?

android - 使用 Glide 将图像 URL 加载到 Kotlin AppWidget

android - 失败:生成失败,发生异常。在volley\bintray.gradle中

Gradle 项目,子项目重复执行

gradle - 删除不包含gradle中文件的子目录

android - ARCore AnchorNode.setOnTapListener

kotlin - 如何在 Kotlin PSI 中获得类的完全限定域名?

kotlin - IntelliJ/Kotlin PSI 中的注释与注释条目