0

I am unable to build my code which makes use of hibernate to generate some classes and google error prone for static code analysis. I thought I enabled the java.sql module, but I am still unable to generate classes for Hibernate so my compilation fails:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project model: Fatal error compiling: CompilerException: InvocationTargetException: java.lang.NoClassDefFoundError: java/sql/Date: java.sql.Date -> [Help 1]

This is in my build section:

<plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>${maven.compiler.plugin.version}</version>
          <configuration>
            <compilerId>javac-with-errorprone</compilerId>
            <forceJavacCompilerUse>true</forceJavacCompilerUse>
            <source>${java.version}</source>
            <target>${java.version}</target>
            <compilerArgs>
              <arg>--add-modules</arg>
              <arg>java.sql</arg>
            </compilerArgs>
            <compilerArguments>
              <endorseddirs>${endorsed.dir}</endorseddirs>
            </compilerArguments>
          </configuration>
          <dependencies>
            <dependency>
              <groupId>org.codehaus.plexus</groupId>
              <artifactId>plexus-compiler-javac-errorprone</artifactId>
              <version>2.8.4</version>
            </dependency>
            <!-- override plexus-compiler-javac-errorprone's dependency on
                             Error Prone with the latest version -->
            <dependency>
              <groupId>com.google.errorprone</groupId>
              <artifactId>error_prone_core</artifactId>
              <version>2.3.1</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-jpamodelgen -->
            <dependency>
              <groupId>org.hibernate</groupId>
              <artifactId>hibernate-jpamodelgen</artifactId>
              <version>5.2.12.Final</version>
            </dependency>
            <!-- Added for modularity JDK 9+ -->
            <dependency>
              <groupId>javax.xml.bind</groupId>
              <artifactId>jaxb-api</artifactId>
              <version>2.3.0</version>
            </dependency>
            <dependency>
              <groupId>com.sun.xml.bind</groupId>
              <artifactId>jaxb-core</artifactId>
              <version>2.3.0</version>
            </dependency>
            <dependency>
              <groupId>com.sun.xml.bind</groupId>
              <artifactId>jaxb-impl</artifactId>
              <version>2.3.0</version>
            </dependency>
          </dependencies>
        </plugin>

According to this: https://github.com/google/error-prone/issues/448

It should work as long as it is configured.

Walter
  • 1,290
  • 2
  • 21
  • 46
  • 1
    The sql Date is in a different module in Java9 ..apart from that why are you defining all theses dependencies as plugin dependencies and not as build dependencies? I have my doubts it's correct... – khmarbaise May 18 '18 at 17:50
  • I believe they're needed by the hibernate plugin for building. – Walter May 18 '18 at 19:57
  • The java.sql module is resolved by default when compiling code on the class path so I assume `--add-modules java.sql` is not needed. Is there a custom class loader in the picture that is delegating to the boot loader instead of the system class loader? That would explain it as the defining loader for the java.sql types is the platform class loader since JDK 9. – Alan Bateman May 19 '18 at 05:59
  • I'm not sure, I know that removing error prone from the equation did allow me to compile though (with the java.sql argument). – Walter May 19 '18 at 10:33

0 Answers0