0

我正在尝试添加自定义 Ktlint 规则。以下是我的 gradle 文件

项目级别

buildscript {
repositories {
    google()
    mavenCentral()
    maven {url "https://plugins.gradle.org/m2/"}
}
dependencies {
    classpath "com.android.tools.build:gradle:7.0.2"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30"
    classpath "org.jlleitschuh.gradle:ktlint-gradle:10.2.0"
  }
}
allprojects {
       apply plugin: "org.jlleitschuh.gradle.ktlint"
}

应用程序的 gradle 文件

        plugins {
        id 'com.android.application'
        id 'kotlin-android'
    }
    
    android {
        compileSdk 31
    
        defaultConfig {
            applicationId "com.example.testktlint"
            minSdk 21
            targetSdk 31
            versionCode 1
            versionName "1.0"
    
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_11
            targetCompatibility JavaVersion.VERSION_11
        }
        kotlinOptions {
            jvmTarget = '1.8'
        }
    }
    
    dependencies {
    
        implementation 'androidx.core:core-ktx:1.6.0'
        implementation 'androidx.appcompat:appcompat:1.3.1'
        implementation 'com.google.android.material:material:1.4.0'
        implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
        testImplementation 'junit:junit:4.+'
        androidTestImplementation 'androidx.test.ext:junit:1.1.3'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
        ktlintRuleset project(":customruleset")
    }

我添加了另一个模块“customruleset”,它的 gradle 文件如下:

        plugins {
        id 'com.android.library'
        id 'kotlin-android'
    }
    
    android {
        compileSdk 31
    
        defaultConfig {
            minSdk 21
            targetSdk 31
            versionCode 1
            versionName "1.0"
    
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
            consumerProguardFiles "consumer-rules.pro"
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
        kotlinOptions {
            jvmTarget = '1.8'
        }
    }
    
    dependencies {
    
        implementation 'androidx.core:core-ktx:1.6.0'
        implementation 'androidx.appcompat:appcompat:1.3.1'
        implementation 'com.google.android.material:material:1.4.0'
        testImplementation 'junit:junit:4.+'
        androidTestImplementation 'androidx.test.ext:junit:1.1.3'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
        compileOnly 'com.pinterest.ktlint:ktlint-core:0.42.1'
    }

当我运行 gradlew ktlintcheck 时出现以下错误

在此处输入图像描述

4

0 回答 0