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

jcabi-github requires Hamcrest to get a http request #1668

Open
volodya-lombrozo opened this issue Aug 6, 2023 · 2 comments
Open

jcabi-github requires Hamcrest to get a http request #1668

volodya-lombrozo opened this issue Aug 6, 2023 · 2 comments

Comments

@volodya-lombrozo
Copy link
Contributor

I tried to use jcabi-github library in order to get some statistics from repos and during the first run get the next exception:

Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/Matcher
	at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
	at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3429)
	at java.base/java.lang.Class.getConstructor0(Class.java:3634)
	at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2810)
	at com.jcabi.http.request.DefaultResponse.as(DefaultResponse.java:161)
	at com.jcabi.github.RtJson.fetch(RtJson.java:76)
	at com.jcabi.github.RtRepo.json(RtRepo.java:250)
	at com.jcabi.github.RepositoryStatistics.toMap(RepositoryStatistics.java:70)
	at com.jcabi.github.RepositoryStatistics$Smart.integer(RepositoryStatistics.java:282)
	at com.jcabi.github.RepositoryStatistics$Smart.forks(RepositoryStatistics.java:226)
	at filter.statistics.GitHubMetrics.cells(GitHubMetrics.java:30)
	at filter.statistics.StatisticsComposite.cells(StatisticsComposite.java:29)
	at filter.statistics.StatisticsCaseLibrary.cells(StatisticsCaseLibrary.java:35)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:1006)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at filter.Report.make(Report.java:28)
	at filter.FilterLibraries.main(FilterLibraries.java:198)
Caused by: java.lang.ClassNotFoundException: org.hamcrest.Matcher
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 22 more

The reason is obvious - my app can't find Hamcrest classes in the classpath. It is rather confusing. Why do I need to keep a testing library in runtime? Of course, adding the next library helped me (pay attention to the scope):

<dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>hamcrest</artifactId>
    <version>2.2</version>
    <scope>compile</scope>
</dependency>

But maybe it is better to fix the plugin to avoid usage of testing libraries in runtime?

@0crat 0crat added the 0crat/new label Aug 6, 2023
@yegor256
Copy link
Member

@volodya-lombrozo we need this library for jcabi-http, it helps us do assertions on HTTP responses that we receive: https://http.jcabi.com/optional-dependencies.html

@volodya-lombrozo
Copy link
Contributor Author

volodya-lombrozo commented Aug 30, 2023

@yegor256 From the link you sent me:

The Hamcrest dependencies are required if you need to use the com.jcabi.http.mock classes

But I didn't use any mocks here. So why do I need Hamcrest then? Maybe it's better to create a separate HTTP response handler to avoid using hamcrest in runtime?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants