Hey, I am trying to make some changes in the java ...
# announcements
Hey, I am trying to make some changes in the java sdk and test them. How have you created the jar from the code bcoz I seem to run into a lot of ClassNotFound errors for OkHttp and Gson transitive dependencies?
the project uses gradle and the distributed builds are built by jitpack. • page on jitpack: https://jitpack.io/#growthbook/growthbook-sdk-java • example build log from jitpack: https://jitpack.io/com/github/growthbook/growthbook-sdk-java/0.5.0/build.log the
file has the build configuration: https://github.com/growthbook/growthbook-sdk-java/blob/main/lib/build.gradle You can also see the github actions workflows that build and test: https://github.com/growthbook/growthbook-sdk-java/tree/main/.github/workflows are you trying to import Gson or OkHttp into your project? they are not exposed and are therefore not available. if you are trying to use Gson and OkHttp directly, you'll need to add them as dependencies to your project. we have specified them as
dependencies rather than
dependencies. here's a snippet from the gradle docs:
Dependencies appearing in the
configurations will be transitively exposed to consumers of the library, and as such will appear on the compile classpath of consumers. Dependencies found in the
configuration will, on the other hand, not be exposed to consumers, and therefore not leak into the consumers' compile classpath. This comes with several benefits:
• dependencies do not leak into the compile classpath of consumers anymore, so you will never accidentally depend on a transitive dependency
• faster compilation thanks to reduced classpath size
• less recompilations when implementation dependencies change: consumers would not need to be recompiled
• cleaner publishing: when used in conjunction with the new
plugin, Java libraries produce POM files that distinguish exactly between what is required to compile against the library and what is required to use the library at runtime (in other words, don’t mix what is needed to compile the library itself and what is needed to compile against the library).
you can learn more about that here: https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_separation this example JVM project implements the growthbook SDK. it does not use OkHttp directly but implements the GBFeatureRepository which does. It does, however, use its own version of Gson: https://github.com/growthbook/examples/tree/main/jvm-spring-web let me know if there's anything else i can answer.
can you tell me more about your setup? when you clone the repository, are you able to run the gradle commands successfully? how are you importing it into your project? do you have any sample code you can share for your project that is trying to use it?
after cloning I'm running gradle jar task and importing it locally in the pom of another project by
Copy code
and just creating the
Copy code
Growthbook growthbook = new Growthbook()
on running the project, it throws the following error
Copy code
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gson/GsonBuilder
	at growthbook.sdk.java.GrowthBookJsonUtils.<init>(GrowthBookJsonUtils.java:28)
	at growthbook.sdk.java.GrowthBookJsonUtils.getInstance(GrowthBookJsonUtils.java:56)
	at growthbook.sdk.java.GrowthBook.<init>(GrowthBook.java:20)
	at com.groww.test.TestApplication.main(TestApplication.java:23)
Caused by: java.lang.ClassNotFoundException: com.google.gson.GsonBuilder
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
while if i import the published jar from jitpack and run the same code, it works fine
not sure why
have you tried any of the following as a temporary workaround: • adding the 2 missing dependencies to your example project • changing
in your cloned code to add the dependencies to your class path i'm not sure you'll be able to access the dependencies this way without adding them to your classpath yourself. this is a related stackoverflow post about this. and according to this one, system scope is deprecated in maven. i haven't used this before but it looks like alternatives are the maven-install-plugin and
goal. https://maven.apache.org/plugins/maven-install-plugin/usage.html This is related to how you're resolving the dependencies locally.
it's working now apparently it was an issue with system scope I resolved it by publishing repo locally using
Copy code
gradle publishToMavenLocal
thanks a lot
amazing, glad to hear! thanks for letting us know 🙌