google/auto

ide instructions in readme

cobbce opened this issue ยท 6 comments

The readme instructions don't mention enabling annotation processing in your ide, and even after doing so my code compiles but intellij 13 CE (OSX) cannot find the generated classes, making the editor show compiler errors.

These instructions for eclipse look promising, but also a pain to have to set up manually.
http://www.codeaffine.com/2014/03/04/using-the-autovalue-code-generator-in-eclipse/

Btw I'm glad to have an alternative to lombok! I like the feature set but we've been plagued with compatibility issues with new ide/java/lombok versions.

Finally able to get everything hooked up, here are the details:
OSX 10.9.2
Intellij 13.1.2 Build #IC 135.690 April 17, 2014
built with gradle 1.12
build.gradle: compile group: 'com.google.auto.value', name: 'auto-value', version: '1.0-rc1'

1:
Properties -> Compiler -> Annotation Processors
check 'Enable annotation processors'
Set 'Store generated sources relative to': Module content root

2: use step b if you are using gradle, otherwise use step a.
a. Module Settings (-> Sources
right click ~/src/my-project/generated and set as source folder

b. It appears that the gradle plugin is overwriting my IDE settings on refresh, removing my addition of the generated folder as a source folder. To get the module source setting to stick, I did the following:

build.gradle: srcDir is additive, so the default srcDir is preserved. The exclude is required because gradle will perform the annotation processing. We are just adding the srcDir tag for the gradle ide integration, gradle will compile successfully without this (but your ide will be busted).
sourceSets.main.java {
srcDir 'generated'
exclude '*/AutoValue.java'
}
3:
Properties -> Compiler -> Excludes
add processor annotation output dir as recursive exclude
ex: ~/src/my-project/generated (recursive)

Explanation:
I'm using gradle with a parent project hierarchy. I was unable to convince the ide to add just the /generated subfolder as a source folder until I had the annotation sources generated outside the project build folder. After taking these two steps (move annotation processor build folder and make it a module source folder), the compiler started failing with a duplicate class error. This is because the annotation processor re-generates the code file, then the compiler tries to process the generated file (because we added it as a source). After excluding the generated folder from the compiler everything is happy (almost).

is there a way to turn on annotation processors using the gradle idea plugin?

having a clean gradle script i can just include to make this all happen would be wonderful!

assuming i can get annotations to be kept to the generated classes, i'd be willing to look into good clean intellij/gradle support :)

Is there some documentation to add autovalue 1.2 manually to an eclipse project. The link in the blog post above was useful but its pretty outdated and deals with the initial release of autovalue.

With the current additions to IntelliJ (https://www.jetbrains.com/idea/whatsnew/#v2016-3-gradle), I'm now using Auto-Value + Gradle in IntelliJ by importing the projects like this:

  • Open the project directory.
  • Select Import Gradle Project.
  • Uncheck "Create separate modules per source set".
  • Select Settings โ†’ Build, Execution, Deployment โ†’ Build Tools โ†’ Gradle โ†’ Runner โ†’ Delegate IDE build/run actions to gradle.
  • Perform an initial Gradle build (you can either run it from within IntelliJ or on the CL via gradlew).
  • Mark build/generated/source/apt/main as a "Generated Sources Root" (right click on the directory โ†’ Mark Directory as โ†’ Generated Sources Root).

Here's an approach that automates most of the configuration from the build file. With some help from this post. In this approach, the annotation processor parts of gradle are picked up and passed into intellij's configuation. Also, the generated sources folded is injected into the configuration. For some reason using the idea plugin generatedSourceDirs doesnt work, so it is just marked as sources.

In this configuration you MUST still uncheck "Create separate modules per source set" when using this. (Haven't figured out how to auto configure this)

idea {
  project {
    ipr {
      withXml { provider ->
        // Get XML as groovy.util.Node to work with.
        def projectXml = provider.asNode()

        // Find compiler configuration component.
        def compilerConfiguration = projectXml.component.find { component ->
          component.'@name' == 'CompilerConfiguration'
        }
        // Replace current annotationProcessing
        // that is part of the compiler configuration.
        def currentAnnotationProcessing = compilerConfiguration.annotationProcessing
        currentAnnotationProcessing.replaceNode {
          annotationProcessing {
            profile(name: 'Default', default: true, enabled: true) {
              processorPath(useClasspath: false) {
                // find all annotation processors on from gradle config and 
                // add them as entries to the intellij config
                project.configurations.annotationProcessor.each {
                  entry(name:"$it.path")
                }
              }
            }
          }
        }
      }
    }
  }
  module {
      // add the generated sources directory as a sourceDir (should be 
      // wherever the intellij compiler is spitting out your autovalue files).
      sourceDirs += file("out/production/classes/generated")
  }
}

we ended up using a plugin to enable this for our IDEs: https://github.com/palantir/gradle-processors