opentimestamps / java-opentimestamps

Other
40 stars 32 forks source link

Java 9+ Dependencies On Java EE Modules #40

Closed cisba closed 4 years ago

cisba commented 4 years ago

With java 9 executing mvn package produces this error:

package javax.xml.bind is not visible
  (package javax.xml.bind is declared in module java.xml.bind, which is not in the module graph)

The issue is explained here.

Fixes on Java 9 and 10 Once you modularized your code, you can declare a regular dependency in the module’s declaration. Until then, --add-modules $module comes to your rescue, which makes sure $module is available and can be added to both java and javac. If you add java.se.ee, you’ll have access to all Java EE modules.

Fixes on Java 11 and later Java 11 removes the Java EE modules, so from then on you will need third-party implementations instead. This StackOverflow answer contains a list of alternatives. Note that using third-party dependencies already works from Java 9 on, so you don’t have to use --add-modules as a stopgap.

cisba commented 4 years ago

I'm not a java expert, so it could be just a workaround (waiting for someone to do a clean PR), but finally I managed to build with two changes in the pom.xml (tested on macOS 10.15.1, maven 3.6.2 and java 9).

  1. added jabx dependency as suggested here:
       <dependency>
           <groupId>org.glassfish.jaxb</groupId>
           <artifactId>jaxb-runtime</artifactId>
           <version>2.3.1</version>
           <scope>runtime</scope>
       </dependency>

Then I encountered a problem with the javadoc plugin:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.9.1:jar (attach-javadocs) on project java-opentimestamps: Execution attach-javadocs of goal org.apache.maven.plugins:maven-javadoc-plugin:2.9.1:jar failed: An API incompatibility was encountered while executing org.apache.maven.plugins:maven-javadoc-plugin:2.9.1:jar: java.lang.ExceptionInInitializerError: null

  1. so I changed the plugin config as suggested here
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-javadoc-plugin</artifactId>
    -                <version>2.9.1</version>
    +                <version>3.1.1</version>
                 <executions>
                     <execution>
                         <id>attach-javadocs</id>
                         <goals>
                             <goal>jar</goal>
                         </goals>
    +                        <configuration>
    +                            <use>false</use>
    +                            <source>1.8</source>
    +                                <links>
    +                                    <link>http://docs.oracle.com/javase/7/docs/api/</link>
    +                                </links>
    +                            <doclint>none</doclint>
    +                        </configuration>
                     </execution>
                 </executions>
             </plugin>
cisba commented 4 years ago

Using openjdk 11 (installed via brew) I encountered the same problems solved with the same changes.