在最新的gradle,Lombok上找不到compileOnly

时间:2017-07-29 15:27:05

标签: android gradle lombok

我试图在我的android项目上设置Lombok,但似乎gradle无法找到 compileOnly 方法。我不知道为什么它会像那样行为不端。此外,我不想使用lombok-gradle插件,因为我不喜欢使用我对项目不了解的随机内容。

这是错误:

Error:(67, 0) Gradle DSL method not found: 'compileOnly()'
Possible causes:
The project 'Experiment1' may be using a version of the Android Gradle plug-in 
that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
- Upgrade plugin to version 2.3.3 and sync projectThe project 'Experiment1' may be 
using a version of Gradle that does not contain the method.
- Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
- Apply Gradle plugin

我的配置文件,app module gradle:

apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId "com.ltx.Experiment1"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    configurations.all { //Solves JSR error
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    //--- Test Libraries ---//
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:2.8.47'

    //--- Code Libraries ---//
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'

    compile 'com.google.code.gson:gson:2.8.1'

    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.squareup.retrofit2:converter-gson:2.3.0'
    compile 'com.squareup.okhttp3:okhttp:3.8.1'
    compile 'com.squareup.okhttp3:logging-interceptor:3.8.1'

    compileOnly "org.projectlombok:lombok:1.16.18"
}

Project gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'me.tatarka:gradle-retrolambda:3.2.5'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

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

打包机:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

1 个答案:

答案 0 :(得分:1)

取代插件,试试这个

compileOnly 'javax.annotation:javax.annotation-api:1.2'
compileOnly "org.projectlombok:lombok:1.16.18"
annotationProcessor "org.projectlombok:lombok:1.16.18"