Packing/Exporting dependencies via Gradle

Hi everyone,
I have some proto files in my Project A and am using the protobuf plugin to generate the java files.
In another gradle file, I’m creating a JAR so I can upload it to the cloud and download in the Project B.
The problem I’m having is with the dependencies since packing them along with the java files in this JAR, would not be ideal because of the file size(~10MB).
So, what would be the best way to have these dependencies in the Project B and in any other project that needs to access those java classes??
Thanks in advance

Ps: Creating a Fatjar would not solve my problem

Gradle and maven solve the problem of transitive dependencies. What went wrong in your case?

@darksnake thanks for replying!

The problem is that, in order to create a stub(gRPC) for example, I would have to manually add “io.grpc:grpc-stub” and “” as dependencies in gradle of Project B, which is what I was trying to avoid.
All I wanted is to generated the jar in Project A, add it in Project B as dependency(implementation files(‘libs/generated_classes.jar’)) and be able to create a stub.

Here’s how I’m creating the jar file:

task sourcesJar(type: Jar) {
    from sourceSets.main.allSource
    archiveClassifier = 'sources'
task javadocJar(type: Jar) {
    from javadoc.destinationDir
    archiveClassifier = 'javadoc'
jar {
    archiveBaseName = 'generated_classes'

sourceSets { += 'src/main/java'

Makes sense? :slight_smile:

Sorry, but I do not understan what are you trying to achieve. If you need your dependency for your final project, it should be declared as transitive. If you need the dependency only to generate some code and then to be excluded from other artifacts, it could be declared with compileOnly configuration classifier. I that case it will be available during compilation, but won’t be added to list of required dependencies in the distribution.

Sorry for the confusion @darksnake, I’m still new to Gradle/Kotlin.

What went wrong in your case?

As the io.grpc dependency is not being included in the jar file, I wouldn’t be able to use, for example, the io.grpc.ManagedChannelBuilder class in the consumer project, unless I manually add to its gradle file as a dependency.
Ideally, once this generated library(jar) is added to the consumer project, I would be ready to use anything from the io.grpc lib.

If your code is generated inside your project, it will be included as a part of your distribution, you do not need to write anything explicitly. Of course, if you use java version of grpc, you need to activate java plugin alongside kotlin plugin. Now if you want to include runtime dependencies, you need to add them to dependencies block.

If you are not familiar with the classpath concept and how generated classes are managed in runtime and how gradle manages dependencies, you probably should start with grpc tutorials for java/kotlin. There are a lot of them out there. For example, you can take the official one.

Cool. Thanks