使用Android Studio 3 RC2获取错误“package lombok不存在”

时间:2017-10-22 14:36:20

标签: java android lombok android-studio-3.0

尝试编译项目时出现以下错误:

  

错误:包lombok不存在

其他人声称无法找到所有注释。

我在编译之前没有看到代码中的错误,而且在使用Android Studio 3 RC1时没有出现此错误。

以下是我的gradle脚本:

项目级别:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-rc2'


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

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

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

应用模块级别:

apply plugin: 'com.android.application'

android {
        compileSdkVersion 26
        buildToolsVersion "26.0.2"
        defaultConfig {
            applicationId "com.mk.forum"
            minSdkVersion 25
            targetSdkVersion 26
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }

        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:26.1.0'
        implementation 'com.android.support.constraint:constraint-layout:1.0.2'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.1'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
        compile project (':util')
        compile project (':forum_core')
        compileOnly 'org.projectlombok:lombok:1.16.18'
        annotationProcessor 'org.projectlombok:lombok:1.16.18'
        compile group: 'com.github.javafaker', name: 'javafaker', version: '0.13'
    }

我也有模块,但我认为这并不重要。

2 个答案:

答案 0 :(得分:2)

我希望这是因为compileOnly注释。这是文档:  blog.gradle.org/introducing-compile-only-dependencies

  
      
  • 编译时需要但在运行时从不需要的依赖项,例如仅源注释或注释处理器;

  •   
  • 编译时需要的依赖关系,但仅在运行时才需要使用某些功能,a.k.a。可选依赖项;

  •   
  • 在编译时需要API但其实现由消费库提供的依赖项,应用程序
      或运行时环境。

  •   

答案 1 :(得分:0)

它可能与jdk9有关。我知道IntelliJ,lombok 1.16.18和jdk9的组合目前还不起作用。但这并不能解释您的错误消息。我们希望我们可以在几天内(也许是今晚)发布1.16.20来解决这个问题。

披露:我是一名lombok开发者。