Immutables do not generate code with java 9 with modules

Using immutables-library works fine with java 9, until I add module-info.java to the project, Immutables*.java will no longer be generated.

In the info module, I add the value "required value" as suggested by IntelliJ.

What I am missing is the immutables-library problem or something else that I need to configure for javac to find annotation processing.

I am using maven with maven-compiler-plugin:3.7.0 configured for target / source = 9 .

+5
source share
1 answer

The problem is that you did not configure the immutable part as an annotation handler, which should run as follows:

 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>example</groupId> <artifactId>jigsaw</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.immutables</groupId> <artifactId>value</artifactId> <version>2.5.6</version> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</version> <configuration> <source>9</source> <target>9</target> <annotationProcessorPaths> <dependency> <groupId>org.immutables</groupId> <artifactId>value</artifactId> <version>2.5.6</version> </dependency> </annotationProcessorPaths> </configuration> </plugin> </plugins> </build> </project> 

In addition to coding tips that can simply be fixed by defining such an encoding as follows:

 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>example</groupId> <artifactId>jigsaw</artifactId> <version>1.0-SNAPSHOT</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.immutables</groupId> <artifactId>value</artifactId> <version>2.5.6</version> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.7.0</version> <configuration> <source>9</source> <target>9</target> <annotationProcessorPaths> <dependency> <groupId>org.immutables</groupId> <artifactId>value</artifactId> <version>2.5.6</version> </dependency> </annotationProcessorPaths> </configuration> </plugin> </plugins> </build> </project> 

If you build this configuration, you will get everything you need:

 . ├── pom.xml ├── src │  └── main │  └── java │  ├── example │  │  └── Some.java │  └── module-info.java └── target ├── classes │  ├── example │  │  ├── ImmutableSome$1.class │  │  ├── ImmutableSome$Builder.class │  │  ├── ImmutableSome.class │  │  └── Some.class │  └── module-info.class ├── generated-sources │  └── annotations │  └── example │  └── ImmutableSome.java ├── jigsaw-1.0-SNAPSHOT.jar ├── maven-archiver │  └── pom.properties └── maven-status └── maven-compiler-plugin └── compile └── default-compile ├── createdFiles.lst └── inputFiles.lst 
+5
source

Source: https://habr.com/ru/post/1272245/


All Articles