Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ide instructions in readme #106

Open
cobbce opened this issue May 24, 2014 · 6 comments
Open

ide instructions in readme #106

cobbce opened this issue May 24, 2014 · 6 comments
Labels
Component: value P3 type=documentation Documentation that is other than for an API

Comments

@cobbce
Copy link

cobbce commented May 24, 2014

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.

@cobbce
Copy link
Author

cobbce commented May 24, 2014

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).

@jmcampanini
Copy link
Contributor

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 :)

alicederyn added a commit to inferred/FreeBuilder that referenced this issue Mar 10, 2015
…t these extra steps, the project builds successfully, but the generated classes are still flagged as unresolved in the UI.)
@cgruber cgruber added Component: value type=documentation Documentation that is other than for an API labels Apr 6, 2016
ducky-hong added a commit to xeoh/GCTool that referenced this issue May 17, 2016
parboiled is PEG (Parsing Expression Grammar) implementation.
PEG is more concise than regex, and regex could not handle recursive
structure well.

GcEventNode is added to access the parsed data easily. Its concrete class is
generated by Auto Value library which utilizes annotation processing. IDE setup
is required and the instruction can be found here:
    google/auto#106
@JW-Vinay
Copy link

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.

@andredasilvapinto
Copy link

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).

@loosebazooka
Copy link

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")
  }
}

@jmcampanini
Copy link
Contributor

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

@raghsriniv raghsriniv added the P3 label Jun 24, 2019
@kluever kluever added P2 and removed P3 labels Aug 16, 2019
@cpovirk cpovirk added P3 and removed P2 labels Jan 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: value P3 type=documentation Documentation that is other than for an API
Projects
None yet
Development

No branches or pull requests

9 participants