Seagate / cortx-s3server

CORTX S3 compatible storage server for CORTX
https://github.com/Seagate/cortx
Apache License 2.0
36 stars 87 forks source link

Possible Jar hell when build auth/server #1566

Open kiwionly2 opened 2 years ago

kiwionly2 commented 2 years ago

Hi,

While I try to compile the java server, I had found that current jar dependencies might create a jar hell. ( It might be an issue if we upgrade build tool in future and thing might no longer work, I am using Gradle to build and it actually produce an error)

This is cause by JUnit library loading hamcrest version is difference then the one inside Mockito ( you could see that is lot more class in hamcrest 1.3 which is transitive load by JUnit 4.13.1.

image

The issue could occurs if the build tool of java class loader is loading the class from Mockito's hamcrest before loading the one from hamcrest jar.

E.g. say a test class import CoreMatchers ( A lot of test classes in auth/server is import this )

import static org.hamcrest.CoreMatchers.containsString;

And the build tool class loader is load the CoreMatchers class in Mockito, it will give compile error. ( because no containsString() method found)

image

Because the correct CoreMatchers class should be the one in hamcrest jar

image

Suggestion solution:

Upgrade Mockito library and we could also could upgrade hamcrest library to latest version

In pom.xml

<groupId>org.mockito</groupId>
    <artifactId>mockito-core</artifactId>
    <version>4.0.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>hamcrest-core</artifactId>
    <version>2.2</version>
    <scope>test</scope>
</dependency>

Now the version of Mockiti, the jar file no longer contain org.hamcrest.*

image

Then in all the test classes, migrate code from

import static org.mockito.Matchers.*;

to

import static org.mockito.Mockito.*;

So align with new version of Mockito.

welcome[bot] commented 2 years ago

Thanks for opening this issue. A contributor should be by to give feedback soon. In the meantime, please check out the contributing guidelines and explore other ways you can get involved.

hessio commented 2 years ago

Hi @kiwionly2  can you provide the steps you followed to produce this issue and I will try to reproduce this myself

kiwionly2 commented 2 years ago

@hessio, is a bit tricky to reproduce this error, this is very much depend on the java class loader ( depend which jar file it load first)

So far I use maven (version 3.6.2 ) not able to reproduce the error.

However, I write a Gradle (version 7.2) build script and try to build the jar, it show this error.

Let me know if you want the Gradle build script, I could send to you for try out.

kiwionly2 commented 2 years ago

@hessio

I created a branch so you could easier reproduce error.

Steps as below( assume run on your machine with any open JDK 1.8 installed )

  1. checkout branch.
  2. cd auth/server
  3. then run ..\gradlew build , gradlew ( gradlew wrapper) will automatic install on your machine and run the build command. You will able to see the error when compile fail.

image

stale[bot] commented 2 years ago

This issue/pull request has been marked as needs attention as it has been left pending without new activity for 4 days. Tagging @nileshgovande @bkirunge7 @knrajnambiar76 @t7ko-seagate for appropriate assignment. Sorry for the delay & Thank you for contributing to CORTX. We will get back to you as soon as possible.

bkirunge7 commented 2 years ago

Thanks kiwionly2 for reporting this issue, @shalakadharap can you please review this and create a Jira story

hessio commented 2 years ago

Hi @shalakadharap were you able to create a Jira issue for this issue?

cortx-admin commented 2 years ago

For the convenience of the Seagate development team, this issue has been mirrored in a private Seagate Jira Server: https://jts.seagate.com/browse/EOS-26087. Note that community members will not be able to access that Jira server but that is not a problem since all activity in that Jira mirror will be copied into this GitHub issue.

stale[bot] commented 2 years ago

This issue/pull request has been marked as needs attention as it has been left pending without new activity for 4 days. Tagging @nileshgovande @bkirunge7 @knrajnambiar76 @t7ko-seagate for appropriate assignment. Sorry for the delay & Thank you for contributing to CORTX. We will get back to you as soon as possible.