Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

module has been deprecated and marked for removal

I've added requires transitive java.activation to my module-info.java, but java-10 is giving me a compiler warning module-info.java: module java.activation has been deprecated and marked for removal, despite my having added a dependency on com.sun.activation:javax.activation:1.2.0 (Automatic-Module-Name: java.activation) to my Maven pom.xml.

I can work around this by adding @SuppressWarnings("removal") to my module declaration, but I never like supressing warnings I could be fixing. Is there something else I could be doing to communicate to the compiler my intention to depend on the third party jar and not the built-in/deprecated version of that module?

Much Thanks!

like image 836
Chris Hubick Avatar asked Jun 29 '18 02:06

Chris Hubick


People also ask

Is deprecated and marked for removal Java?

Starting with JDK 9, APIs may be marked as deprecated for removal. This indicates that the API is eligible to be removed in the next release of the JDK platform. If your application or library consumes any of these APIs, then you should make a plan to migrate from them soon.

Has been deprecated Java?

Similarly, when a class or method is deprecated, it means that the class or method is no longer considered important. It is so unimportant, in fact, that it should no longer be used at all, as it might well cease to exist in the future. The need for deprecation comes about because as a class evolves, its API changes.


Video Answer


1 Answers

Analysis

The option --show-module-resolution helps observe such behavior. It is only available on java, not javac, but the JPMS behaves the same in both cases. If you launch the app with that option and javax.activation-1.2.0.jar on the module path, you will see this line:

root $your-module file:///$your-jar requires java.activation jrt:/java.activation

Note that java.activation was pulled from jrt:/java.activation, not the JAR on the module path. The module system prefers (unfortunately silently) the platform module over one from the module path, which is why your non-deprecated version is not used.

Solutions

I see three different solutions to your problem.

Upgrade Module Path

The JAR you're using is a full implementation of the platform module java.activation and you can hence use the JAR to replace the module by putting the JAR on the upgrade module path:

javac
    -d /home/nipa/code/Java-Activation/target/classes
    --upgrade-module-path ~/.m2/repository/com/sun/activation/javax.activation/1.2.0/javax.activation-1.2.0.jar:
    -g --release 10 -encoding UTF-8
    `find . -name *.java`

The compiler will then use the JAR to replace the platform module of the same name and the deprecation goes away.

As you discovered yourself, you can configure the compiler plugin with the command line option:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <compilerArgs>
                    <arg>--upgrade-module-path=${settings.localRepository}/com/sun/activation/javax.activation/${javax.activation.version}/javax.activation-${javax.activation.version}.jar</arg>
                </compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>

Java 11

The JEE modules, like java.activation, have been removed from JDK 11, so if you build against 11, the problem goes away.

Ignore It

You're doing the right thing and it will sort itself out in a few months, so go ahead and ignore the warning. :)

like image 94
Nicolai Parlog Avatar answered Oct 23 '22 04:10

Nicolai Parlog