user1002065
user1002065

Reputation: 615

dependencies for a library jar using gradle

I am using gradle 6.7 and creating a library project which is compiled to a jar that is placed in my own s3 artifacts repository.

In my project I have dependencies to other artifacts and I use implementation dependency.

The jar is created (not a fat jar) and uploaded to the s3 repository.

When in another project I am using my library by fetching it as implementation dependency I am getting errors NoClassDef for other dependencies I used in my library, which means that no runtime is found for the dependencies I was using in my library.

My question is, whether it is a good idea to create a fat jar? I don't think that other libraries (e.g. springboot and others) are using fat jars, right? however when I use them as dependency other dependencies are found on runtime.

Does it mean that using implementation in my project for other dependencies is not the right way? shall I use something else? Could you please contribute a bit more about what is the right way?

Thank you

Upvotes: 2

Views: 986

Answers (1)

Zack
Zack

Reputation: 301

Check out the Java Library Plugin for gradle. It exists for this exact situation.

If a dependency of your library needs to be exposed to the consumer of your library, then you would use api instead of implementation. There is a nice section within the plugin documentation here that can be used to help you identify when to declare a dependency as api vs implementation.

Upvotes: 1

Related Questions