How to make GitHub's Immutables work in IntelliJ + Gradle
Found the answer. Sharing in case it will be helpful to anyone (or myself in the future).
First of all, I had to enable annotation processing in IntelliJ as described here (though the option is now located in Settings > Build, Execution, Deployment > Compiler > Annotation Processors
).
After that the following code started actually generating the implementation:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// immutable entities generation
compile "org.immutables:value:2.5.5" // for annotations
compile "org.immutables:builder:2.5.5" // for annotations
compile "org.immutables:gson:2.5.5" // for annotations
... other dependencies
}
However, I still couldn't automatically import the implementation into source files.
In order to do allow the discovery of the generated classes, I had to right-click on the generated
folder in the main
package and then Mark Directory As > Generated Sources Root
.
I can't add comment (too low rep), but for future readers I want to extend Vasiliy answer.
In my case (gradle wrapper in version 5.2.1) following code auto-magically discovers generated sources:
dependencies {
def immutablesVersion = "2.8.2"
annotationProcessor "org.immutables:value:$immutablesVersion" // <--- this is important
compileOnly "org.immutables:value:$immutablesVersion"
}
I don't need to change anything in IDE annotation processor options, it just works out of the box.