https://www.growthbook.io/ logo
#announcements
Title
# announcements
b

best-quill-79210

03/14/2023, 12:07 PM
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?
b

better-magician-65629

03/14/2023, 5:12 PM
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
build.gradle
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
implementation
dependencies rather than
api
dependencies. here's a snippet from the gradle docs:
Dependencies appearing in the
api
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
implementation
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
maven-publish
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?
b

best-quill-79210

03/14/2023, 8:47 PM
after cloning I'm running gradle jar task and importing it locally in the pom of another project by
Copy code
<dependency>
   <groupId>com.github.growthbook</groupId>
   <artifactId>growthbook-sdk-java</artifactId>
   <version>main-SNAPSHOT</version>
   <scope>system</scope>
   <systemPath>/Users/pranay.garg/Documents/growthbook-sdk-java/lib/build/libs/lib-main-SNAPSHOT.jar</systemPath>
</dependency>
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
b

better-magician-65629

03/14/2023, 9:00 PM
have you tried any of the following as a temporary workaround: • adding the 2 missing dependencies to your example project • changing
implementation
to
api
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
install:install-file
goal. https://maven.apache.org/plugins/maven-install-plugin/usage.html This is related to how you're resolving the dependencies locally.
b

best-quill-79210

03/15/2023, 9:42 AM
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
b

better-magician-65629

03/21/2023, 7:53 PM
amazing, glad to hear! thanks for letting us know 🙌
14 Views