Open artemik opened 6 years ago
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?
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?
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)
}
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:
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:
package sample;
import net.karneim.pojobuilder.GeneratePojoBuilder;
@GeneratePojoBuilder
public class Contact {
public String name;
public int age;
}
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.)
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.
This was a support question and the author never stated they are use Gradle. Should be closed.
generated-sources/annotations
folder added to the IDE. This is a pretty standard dance for all annotation-processors/code-generators in IntelliJ
Is there going to be Intellij IDEA support?