使用不变库可以很好地处理java 9,直到我将module-info.java添加到项目中为止,Immutables*.java将不再生成。
在模块-info中,我添加了IntelliJ建议的“所需值”。
我缺少的是什么,是immutables-library问题还是我需要设置的其他东西,以便javac找到注释处理。
我使用的是maven-compiler-plugin:3.7.0配置为目标/源代码= 9的maven。
发布于 2017-09-30 11:48:55
您遇到的问题是,您还没有将不可变部分配置为一个注释处理器,应该这样做:
<?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>除了有关编码的提示之外,还可以简单地通过这样定义编码来修复这些提示:
<?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>如果您通过上述配置进行构建,您将得到所需的所有内容:
.
├── 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.lsthttps://stackoverflow.com/questions/46500984
复制相似问题