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

Intellij IDEA support #149

Open
artemik opened this issue Feb 23, 2018 · 6 comments
Open

Intellij IDEA support #149

artemik opened this issue Feb 23, 2018 · 6 comments

Comments

@artemik
Copy link

artemik commented Feb 23, 2018

Is there going to be Intellij IDEA support?

@artemik
Copy link
Author

artemik commented Feb 23, 2018

I've just found out support is out there.
I needed to compile project and mark the generated folder as generated sources root. But the documentation does't seem to indicate that.
Could you please add it?

@mkarneim
Copy link
Owner

Hi Artemik,

Since I haven't used it so far, I didn't include any docs about how to enable PB in IntelliJ IDEA.
I'm glad that you managed it anyway.

My question is now, would you be so kind to provide some lines that I can add to the PB documentation, so that a typical IntelliJ user could follow it easy?

@PickySalamander
Copy link

It's not perfect, but I was able to get my build / intellij working with the following added to my Gradle script:

apply plugin: 'idea'

ext {
  generatedSourcesRoot = "${projectDir}/src/generated-sources/java"
}

compileJava.options.compilerArgs += ['-s', generatedSourcesRoot]

idea.module {
  generatedSourceDirs += file(generatedSourcesRoot)
  sourceDirs += file(generatedSourcesRoot)
}

@mkarneim
Copy link
Owner

Thank you for this hint.
However, it seems that this is not enough for creating some valid idea project files.

Based on your code snippet I created the following sample project:

build.gradle

apply plugin: 'idea'
apply plugin: 'java'

ext {
  generatedSourcesRoot = "${projectDir}/src/generated-sources/java"
}

compileJava.options.compilerArgs += ['-s', generatedSourcesRoot]

idea {
  project {
    jdkName = '1.8'
    languageLevel = '1.8'
  }
  module {
    generatedSourceDirs += file(generatedSourcesRoot)
    sourceDirs += file(generatedSourcesRoot)
  }
}

repositories {
  mavenCentral()
}

dependencies {
  compile     'net.karneim:pojobuilder:4.2.2'
  testCompile 'org.assertj:assertj-core:2.8.0'
  testCompile 'junit:junit:4.12'
}

Then I added the following two classes:

src/main/java/sample/Contact.java

package sample;

import net.karneim.pojobuilder.GeneratePojoBuilder;

@GeneratePojoBuilder
public class Contact {
  public String name;
  public int age;
}

src/test/java/sample/ContactTest.java

package sample;
import org.junit.Test;
import org.assertj.core.api.Assertions;

public class ContactTest extends Assertions {
  @Test
  public void test() {
    ContactBuilder underTest = new ContactBuilder();
    Contact act = underTest.withName("blah").build();
    assertThat(act.name).isEqualTo("blah");
  }
}

Finally I executed gradlew idea from the command line and then opened the project folder with Idea.

When I now invoke "Build > Build Project" I just get the following compile error:

C:\devel\workspace\pojobuilder-idea-sample\src\test\java\sample\ContactTest.java
Error:(8, 5) java: cannot find symbol
  symbol:   class ContactBuilder
  location: class sample.ContactTest
Error:(8, 36) java: cannot find symbol
  symbol:   class ContactBuilder
  location: class sample.ContactTest

So I guess something is missing :-/

(By the way: building this project from the command line using Gradle works fine.)

@Poeschl
Copy link
Contributor

Poeschl commented Nov 7, 2018

If its still a thing, I put my everyday configs for that in a little example project ;)
https://github.com/Poeschl/Pojobuilder-Sourceset-Example

I use a dedicated sourceset for the generated classes, so it works out of the box for Intellij and eclipse.

@drekbour
Copy link
Contributor

drekbour commented Mar 4, 2019

This was a support question and the author never stated they are use Gradle. Should be closed.

  • With Maven, you need to import, compile, re-import to get the generated-sources/annotations folder added to the IDE. This is a pretty standard dance for all annotation-processors/code-generators in IntelliJ
  • With Gradle, the wiki has several cookbook examples that should cover this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants