Issue
I get the following errors when compiling with Java 11.
Symbol is declared in module 'java.xml' which does not export package 'com.sun.org.apache.xerces.internal.xni.parser'
Symbol is declared in module 'java.base' which does not export package 'sun.net.www.protocol.http'
Symbol is declared in module 'java.base' which does not export package 'sun.net.www.protocol.file'
Symbol is declared in module 'java.xml' which does not export package 'com.sun.org.apache.xerces.internal.util'
Symbol is declared in module 'java.xml' which does not export package 'com.sun.org.apache.xerces.internal.xni.parser'
Symbol is declared in module 'java.xml' which does not export package 'com.sun.org.apache.xerces.internal.xni.parser'
Symbol is declared in module 'java.xml' which does not export package 'com.sun.org.apache.xerces.internal.xni.parser'
[...]
Symbol is declared in module 'java.xml' which does not export package 'com.sun.org.apache.xerces.internal.impl.dtd'
I need to specified --add-exports
directive to the Java compilation.
I don't know how to add it to my Maven build compiling Kotlin code.
Also, I am not sure about the exact values for --add-exports
.
This is my pom.xml
.
<!-- Kotlin compilation -->
<build>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/main/java</source>
<source>src/main/kotlin</source>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
<!-- Bundle a standalone JAR -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>${project.artifactId}-${project.version}-all</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>DtdFinderKt</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- Attempt to specify --add-export -->
<profiles>
<profile>
<id>java11-compiler-java-with-kotlin</id>
<activation>
<file><exists>${basedir}/src/main/kotlin</exists></file>
<jdk>[11,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>--add-exports</arg><arg>java.xml/com.sun.org.apache.xerces.internal.impl.dtd=ALL-UNNAMED</arg>
<arg>--add-exports</arg><arg>java.xml/com.sun.org.apache.xerces.internal.xni.parser=ALL-UNNAMED</arg>
<arg>--add-exports</arg><arg>java.base/sun.net.www.protocol.http=ALL-UNNAMED</arg>
<arg>--add-exports</arg><arg>jdk.unsupported/sun.misc=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Solution
The solution is to include an annotation at the beginning of each source file using the internal APIs.
@file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE")
This annotation was found because of this thread on Kotlin support forum.
Answered By - h3xStream
Answer Checked By - Mary Flores (JavaFixing Volunteer)