Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work with JDK 8 bsed project #25

Closed
rvsoni opened this issue Dec 4, 2020 · 18 comments
Closed

Does not work with JDK 8 bsed project #25

rvsoni opened this issue Dec 4, 2020 · 18 comments
Labels
bug Something isn't working

Comments

@rvsoni
Copy link

rvsoni commented Dec 4, 2020

The plugin is built on Java 11, so not possible to use with a project using jdk 8.

Throws exception,

[ERROR] Failed to execute goal se.kth.castor:depclean-maven-plugin:1.1.0:depclean (default) on project idsk-commons-media: Execution default of goal se.kth.castor:depclean-maven-plugin:1.1.0:depclean failed: An API incompatibility was encountered while executing se.kth.castor:depclean-maven-plugin:1.1.0:depclean: java.lang.NoSuchMethodError: java.nio.ByteBuffer.limit(I)Ljava/nio/ByteBuffer;

@cesarsotovalero
Copy link
Collaborator

cesarsotovalero commented Dec 4, 2020

@rvsoni We have downgraded DepClean to Java 8 (see 2faeb21).

Does it work for you now?

@rvsoni
Copy link
Author

rvsoni commented Dec 5, 2020

Thanks for updating for JDK8,

I guess, You will have to make a release of this plugin, as the current 1.1.0 release is with JDK11 support and available from public Maven Repo, so the new release has to push on the Maven repo with an updated version so we can start using this maven plugin.

I tested fix locally by building the project,

Thanks,
Ravi

@cesarsotovalero
Copy link
Collaborator

Hi @rvsoni, DepClean is available for JDK 8 in Maven Central. See it at https://search.maven.org/artifact/se.kth.castor/depclean-parent-pom/1.1.0/pom

Please close this issue if it works for you.
Also, consider giving this project a ⭐, it helps us to grow.
Thanks.

@rvsoni
Copy link
Author

rvsoni commented Dec 12, 2020

Hi, @cesarsotovalero

I don't think only updating deapclean-parent-pom:1.1.0 to jdk 8 is enough, I see the same error as only patent pom is updated but the deapclean-maven-plugin is still old jdk11 build,

The maven plugin code for deapclean-maven-plugin:1.1.0 is still old and compiled using JDK11, it's not going to work with jdk8,

MAINFEST.MF of dealclean-maven-plugin:1.1.0
https://repo1.maven.org/maven2/se/kth/castor/depclean-maven-plugin/1.1.0/depclean-maven-plugin-1.1.0.jar

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven 3.6.3
Built-By: cesarsv
Build-Jdk: 11.0.7

You need to recompile all dealclean-maven-plugin code with jdk8 and republish to maven repo to make it working with jdk8.

Thanks,
Ravi

@amottier
Copy link
Contributor

I get the same issue with version 1.1.1 so I tried to investigate a little bit more.

Error is related probably to usage of java.nio.ByteBuffer in: https://github.com/castor-software/depclean/blob/master/depclean-core/src/main/java/se/kth/depclean/core/analysis/asm/ConstantPoolParser.java

A comment mention a workaround to this issue but is not implemented.

I run javap -verbose ConstantPoolParser on ConstantPoolParser.class packaged in depclean-core-1.1.1.jar and get the following output:

  minor version: 0
  major version: 52

According to https://en.wikipedia.org/wiki/Java_class_file#General_layout this confirm that this is some byte code targeting Java 8 even if META-INF/MANIFEST.MF packaged in depclean-core-1.1.1.jar mention Build-Jdk: 15.0.1: JDK 15 can generate byte code for Java 8.

An explanation about this behavior can be found in jetty/jetty.project#3244 (comment)

Actually current pom.xml specify source and target (https://github.com/castor-software/depclean/blob/master/pom.xml#L19) but if Java 9 or higher is used to build the project it should specify the release option (maven.compiler.release) see https://stackoverflow.com/a/43103038/2440340

I will shortly create a pull request that fix the issue and allow successful build on Java 9 or higher (but note that build will failed with Java 8) with error [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project depclean-core: Fatal error compiling: invalid flag: --release -> [Help 1])

I'm not sure if there is an easy solution to allow build of the project with both Java 8 and Java 9+ versions. I guess that requiring Java 9+ version for building is not a big issue and that compatibility with Java 8+ version is what is important here.

amottier added a commit to amottier/depclean that referenced this issue Jan 14, 2021
Use `maven.compiler.release` to avoid runtime issue (see ASSERT-KTH#25).
As `maven.compiler.release` lead to the usage of `-release` `javac` option.
Removed `maven.compiler.source` and `maven.compiler.target` that are no longer useful.
Important: project cannot be build anymore with Java 8 because `javac` version 8 does not support `--release` option added by Maven property `maven.compiler.release`.
@cesarsotovalero
Copy link
Collaborator

@amottier Thanks for the detailed explanation and the PR. For the moment, DepClean is targeting Java 8 bytecode, so specifying the release option as you suggest should fix this issue. I'll merge #29.

@rvsoni WDYT?

@cesarsotovalero cesarsotovalero added the bug Something isn't working label Jan 14, 2021
rvsoni pushed a commit to rvsoni/depclean that referenced this issue Jan 15, 2021
@rvsoni
Copy link
Author

rvsoni commented Jan 15, 2021

Hi @cesarsotovalero

I don't think any code change is required, it needs just one fix related to the maven-compiler-plugin, just forked the existing code and made changes into the "depclean-parent-pom" as follow

Removed
<maven.compiler.release>8</maven.compiler.release>

Added

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

Compiled the code with openjdk version "1.8.0_275" and tested the plugin with "Apache Commons Lang 3.10.1-SNAPSHOT" project,

You can see the project compilation log file (depclean-jdk8.txt) and use of the plugin on "Apache Commons Lang 3.10.1-SNAPSHOT".
pl. review the fix I made and try on jdk 8

Note: pl. clean up your local maven repo folder "/.m2/repository/se/kth/castor/" before compliation to get clean reasult.

You also need to republish the new module to replace the old JDK 11 only code, re-releasing the parent pom only is not enough.

I guess you need to increase the release version, all existing releases are already cached into maven repo and many other maven proxy repos, it would be hard to clean all modules. releasing the new version with JDK 8 support is the only way to move forward.

Ravi

@amottier
Copy link
Contributor

@rvsoni I agree that using maven.compiler.source and maven.compiler.target properties and run the build using JDK 8 (need to update the CI configuration instead of maven.compiler.release with JDK 11 would be a valid solution just as the one I suggested (that by the way does not required any code change).

@rvsoni
Copy link
Author

rvsoni commented Jan 16, 2021

Yes, @amottier, you are correct on fixing this issue by fixing the CI Config to use JDK 8 (i guess OpenJDK) and the correct maven setting will fix this issue,

Note. The entire project has to be re-release (with the new version) to the public maven repo to make it enable to use on JDK8.

@ikysil
Copy link

ikysil commented Feb 9, 2021

This issue is still reproducible with JDK 8 when using latest release of the plugin - 1.1.1

@rvsoni
Copy link
Author

rvsoni commented Feb 9, 2021

@ikysil

This plugin is yet not released with the fix, so the artifacts on the maven repo are not compatible with JDK 8,

Ravi

@mtorres10
Copy link
Contributor

mtorres10 commented Mar 16, 2021

@cesarsotovalero and all team castor-software, want to say this project sounds like a fantastic idea.

I made the changes mentioned by @cesarsotovalero and @rvsoni on this branch, forked from current master built locally to use with a JDK 8 project.

When using it locally I got an error related to nio:

[ERROR] Failed to execute goal se.kth.castor:depclean-maven-plugin:2.0.1-SNAPSHOT:depclean (default-cli) on project TALOSJava: Execution default-cli of goal se.kth.castor:depclean-maven-plugin:2.0.1-SNAPSHOT:depclean failed: An API incompatibility was encountered while executing se.kth.castor:depclean-maven-plugin:2.0.1-SNAPSHOT:depclean: java.lang.NoSuchMethodError: java.nio.file.Path.of(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;

For version 2.0.1-Snapshot another change is required to keep compatibility with JDK 8.

It seems Path.of is not supported in JDK8 need to be changed to Paths.get.

I created this PR to change this: https://github.com/castor-software/depclean/pull/43/files

Appreciate your help with this,

Marco

@mtorres10
Copy link
Contributor

@cesarsotovalero Closed PR as it seems more changes are needed in order to support JDK8 on version 2.0.1-snapshot. Will update all my findings

@cesarsotovalero
Copy link
Collaborator

cesarsotovalero commented Mar 16, 2021

Hi @mtorres10. I downgraded to Java 8 in the past in an attempt to address this issue (see 2faeb21). However, I had to upgrade again to Java 11 since it didn't solve the issue.

@mtorres10
Copy link
Contributor

mtorres10 commented Mar 16, 2021

@cesarsotovalero I was able to successfully build and execute a using JDK8. These are my findings:

  • Change your POM same as your commit.
  • You need to change method Path.of to Paths.get, see this link.
  • You need to clean any previous installation you did on your mave repo (I deleted the corresponding folder in my .m2 folder).
  • You need to do a mvn clean for each project in the depclean solution (not sure this is strictly required but I did it).
  • You need to build/compile using JDK 8 (I used adoptjdk-hotspot 282).

After following those steps I was able to use on a JDK 8 based project without any issues.

Side note: on another project I got some errors when plugin de-compresses some jars (just in a couple of them, not all) and json file was not generated. In order to discard it was due using JDK 8 I migrated that project to JDK 11 and tested using depclean for JDK 11 (straight out of the maven repo) with the same results. (I will take a look to this)

Depclean is a great idea and enabling JDK 8 will open even more opportunities for its usage.

Here is the PR, hope it is helpful: #44

@amottier
Copy link
Contributor

@mtorres10 your PR looks good to me but as CI is configured to use OpenJDK 11 for the build I would recommend to update the pom.xml to use:

<maven.compiler.release>8</maven.compiler.release>

instead of

<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

JEP 247 mention that --release N is equivalent to -source N -target N -bootclasspath <documented-APIs-from-N> (for N < 9) and this -bootclasspath option is important if build is done on OpenJDK 11 in order to prevent issue with java.nio.ByteBuffer.

I open #45 as an alternative that used the solution I'm suggesting in my comment.

@amottier
Copy link
Contributor

@cesarsotovalero thanks for merging the PR 👍 Do you plan to release a 2.0.1 built with this modification? I'm asking because for users who want to use the plugin with Java 8 they currently still need to download the source and build from sources the plugin.

@cesarsotovalero
Copy link
Collaborator

cesarsotovalero commented Mar 17, 2021

Minor release is coming soon...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants