Java 9: Exporting packages to unnamed modules fail

ItachiUchiha :

I am trying to build an open-source project against Java 9. There are some files which I need to access using reflection but I cannot because the packages are not exported by their modules. I export the packages to unnamed modules by using the arguments --add-exports.

I have added the following arguments to environment variable _JAVA_OPTIONS:

-Dsun.reflect.debugModuleAccessChecks=true 
--add-exports=javafx.graphics/com.sun.javafx.scene.traversal=ALL-UNNAMED
--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED

I am using the latest JDK 9 build (as of today):

C:\controlsfx>java -version
java version "9"
Java(TM) SE Runtime Environment (build 9+175)
Java HotSpot(TM) 64-Bit Server VM (build 9+175, mixed mode)

Here is the output when I try to build the project:

C:\controlsfx>.\gradlew :controlsfx:build
Picked up _JAVA_OPTIONS: -Dsun.reflect.debugModuleAccessChecks=true --add-exports=javafx.graphics/com.sun.javafx.scene.traversal=ALL-UNNAMED --add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
:controlsfx:compileJava
C:\controlsfx\controlsfx\src\main\java\impl\org\controlsfx\behavior\SnapshotViewBehavior.java:60: error: package com.sun.javafx.scene.control.behavior is not visible
import com.sun.javafx.scene.control.behavior.BehaviorBase;
                                   ^
  (package com.sun.javafx.scene.control.behavior is declared in module javafx.controls, which does not export it to the unnamed module)

C:\controlsfx\src\main\java\impl\org\controlsfx\ReflectionUtils.java:3: error: package com.sun.javafx.scene.traversal is not visible
import com.sun.javafx.scene.traversal.ParentTraversalEngine;
                           ^
  (package com.sun.javafx.scene.traversal is declared in module javafx.graphics, which does not export it to the unnamed module)

The compilation still fails, which makes me wonder what am I doing wrong.

Nicolai :

It looks like the flags you add (which seem to be the right ones) are not added to the compiler but the process that runs Gradle. An indication of that are the messages that inform you about --illegal-access, which is only available on java, not javac.

When working with Java 9 it can sometimes be tough to get the arguments to the right places. For Gradle this might help.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=433259&siteId=1