Code Monkey home page Code Monkey logo

Comments (6)

andredasilvapinto avatar andredasilvapinto commented on June 20, 2024 4

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

from auto.

jmcampanini avatar jmcampanini commented on June 20, 2024 3

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

from auto.

cobbce avatar cobbce commented on June 20, 2024 2

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

from auto.

jmcampanini avatar jmcampanini commented on June 20, 2024

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

from auto.

JW-Vinay avatar JW-Vinay commented on June 20, 2024

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.

from auto.

loosebazooka avatar loosebazooka commented on June 20, 2024

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

from auto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.