Immutables不会使用带有模块的java 9生成代码

Lar*_* KJ 7 java maven java-platform-module-system java-9 immutables-library

使用immutables-library可以正常使用java 9,直到我添加一个module-info.java项目,Immutables*.java将不再生成.

对于模块信息,我按照IntelliJ的建议添加"需要值".

我缺少什么,是一个immutables-library问题或我需要设置的其他东西,以便javac找到注释处理.

我正在使用maven-compiler-plugin:3.7.0配置为target/source = 9的 maven .

khm*_*ise 7

您遇到的问题是您没有将Immutable部件配置为注释处理器,应该这样做:

<?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>
Run Code Online (Sandbox Code Playgroud)

除了关于编码的提示,可以通过定义这样的编码来修复:

<?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>
Run Code Online (Sandbox Code Playgroud)

如果您通过上述配置构建,您将获得所需的所有内容:

.
??? 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
Run Code Online (Sandbox Code Playgroud)

  • 我已经重新检查了这个.而你是对的.JDK 8和JDK 9之间存在行为更改...提交[问题](https://issues.apache.org/jira/browse/MCOMPILER-310). (5认同)