Cannot resolve symbol with AutoValue and IntelliJ

后端 未结 3 1321
温柔的废话
温柔的废话 2021-02-14 08:45

I have been trying to find the correct settings for IntelliJ\'s annotation processing in order for it to co-exist with Gradle\'s build process.

Whenever I build from Int

相关标签:
3条回答
  • 2021-02-14 09:33

    Just have your build.gradle with these and it works fine, no need of touching intellij, source set etc..

        plugins {
        id 'java'
        id "net.ltgt.apt" version "0.20"
    
    }
    
    apply plugin: 'idea'
    apply plugin: 'net.ltgt.apt-idea'
    group 'abc'
    version '1.0-SNAPSHOT'
    
    sourceCompatibility = 1.8
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        testCompile group: 'junit', name: 'junit', version: '4.12'
        compile             "com.google.auto.value:auto-value-annotations:1.6.2"
        annotationProcessor "com.google.auto.value:auto-value:1.6.2"
    }
    
    0 讨论(0)
  • 2021-02-14 09:39

    The answers are (should be) in the README for the gradle-apt-plugin: https://github.com/tbroyer/gradle-apt-plugin

    Namely, also apply the net.ltgt.apt-idea plugin.

    Btw, I recommend delegating build/run actions to Gradle in IntelliJ. Sure it's a bit slower, but requires zero setup in the IDE and works reliably. That said, it should also work OK if you don't.

    0 讨论(0)
  • 2021-02-14 09:44

    After importing your Gradle project under IDEA do the following steps:

    1. Set annotation processing configuration as follows:

    2. Run menu: Build - Build Project

    3. Right click on each new generated folder and select: Mark Directory as - Generated Sources Root so it was marked as follows:

      1. Add /generated to project's .gitignore file

    That's a minimal viable configuration which will provide full IDE support for generated classes. The drawback is, whenever Gradle project gets re-imported the generated folders will need be marked as Generated Sources Root again. Perhaps this can be improved with adding these paths as source sets under build.gradle.

    Sometimes it happens that IDEA modules lose their compiler output path settings in result of the above. It's sufficient to just set it back to their default folders.

    0 讨论(0)
提交回复
热议问题