Cannot resolve character with AutoValue and IntelliJ

I tried to find the correct settings for processing IntelliJ annotations so that it coexisted with the Gradle build process.

Whenever I build from IntelliJ, I cannot get it to recognize the generated sources from the gradle-apt-plugin plugin .

My requirements for my project:

  • The construction between IntelliJ and Gradle should be seamless and not interfere with each other's process.
  • I need to use IntelliJ. Create a separate module for each source set option.
  • I need to use IntelliJ folder structure
  • IntelliJ should be able to recognize and automatically populate AutoValue classes

Here are the steps for MCVE to reproduce the issue with IntelliJ 2017.2.4 and Gradle 3.5:

  • Create a new Gradle project from IntelliJ
  • Check the box next to "Create a separate module for each source."
  • Open the build.gradle file:
  • Add the following block plugins:

plugins {
    id 'java'
    id 'net.ltgt.apt' version '0.12'
}
  • Add the following block dependencies

dependencies {
    compileOnly 'com.google.auto.value:auto-value:1.5'
    apt 'com.google.auto.value:auto-value:1.5'
}
  • Go to Settings → Build, Run, Deploy → Annotation Processors.
  • Check enable annotation processing
  • Create class:

@AutoValue
public abstract class GeneratedSourcesTest {

    static GeneratedSourcesTest create(String field) {
        return new AutoValue_GeneratedSourcesTest(field);
    }

    public abstract String field();
}
  • On IntelliJ, run Build -> Build Project
  • Open the class GeneratedSourcesTest, everything is fine in the static factory method, but I get an error:

cannot resolve symbol 'AutoValue_GeneratedSourcesTest

How to make a class AutoValue_GeneratedSourcesTestaccessible from IntelliJ?

+7
source share
3 answers

After importing the Gradle project into IDEA, follow these steps:

  1. Set the annotation processing configuration as follows: enter image description here

  2. Launch Menu: Build - Build Project

  3. : - , : enter image description here

    1. /generated .gitignore

, IDE . , , Gradle , Root Generated Sources. , , build.gradle.

, IDEA . .

+6

( ) README gradle -apt-plugin: https://github.com/tbroyer/gradle-apt-plugin

, net.ltgt.apt-idea.

, / Gradle IntelliJ. , , IDE . , , .

+2

build.gradle , , intellij, ..

    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

Source: https://habr.com/ru/post/1686405/


All Articles