9

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

To the module-info I add 'requires value' as suggested by IntelliJ.

What am I missing, is it a immutables-library issue or something else I need to set up in order for javac to find the annotation processing.

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

Naman
  • 27,789
  • 26
  • 218
  • 353
Lars KJ
  • 632
  • 7
  • 15
  • Could you share a sample of the project you're working on. What kind of errors in log if any you see during build etc? – Naman Sep 30 '17 at 09:49
  • Sure https://github.com/LarsKrogJensen/jigsaw-immutables – Lars KJ Sep 30 '17 at 10:37
  • There are no errors during compile, but it does not generate any ImmutableSome.java as it does if I remove the modules-info.java – Lars KJ Sep 30 '17 at 10:39
  • That seems like a lib issue, could you try executing `mvn clean install -X` (debug mode) to see if there's any lead there. Also *works fine with java 9 until I add a module-info.java* seems to be an incorrect assumption, since I believe you might be ending up compiling the code without modules in that case. – Naman Sep 30 '17 at 10:49
  • @LarsKJ You should add supplemental executions in a pom based on the usage of JDK 9...only defined the version of the maven-compiler-plugin...best is define only the version of the plugin via pluginManagement nothing more. I've got the feeling that this is your problem ..I'm not sure how and when the ImmutableSome.java class will be generated... – khmarbaise Sep 30 '17 at 11:37

1 Answers1

10

The problem you have is that you haven't configured the Immutable part as a annotation processor which should be done like this:

<?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>

Apart from hints about encoding which simply can be fixed by defining the encoding like this:

<?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 via the above configuration you will get all the things 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
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Thanx a alot - now maven generates the source. Though I have never had to tell maven in this way - it has always picked it up the annotation processor from the classpath. I guess this will be improved. A minor issue is that Intellij does not pick up this configuration. – Lars KJ Sep 30 '17 at 15:04
  • If you are running with JDK 9 it might be a different story.But I'm not sure about... – khmarbaise Sep 30 '17 at 16:16
  • 5
    I have rechecked this. And you are right. There is a behaviour change between JDK 8 and JDK 9 ...Filed in an [issue](https://issues.apache.org/jira/browse/MCOMPILER-310). – khmarbaise Sep 30 '17 at 16:49