Package multiple Java functions into separate zip files with Gradle

Good day All,

We’re consolidating our code into one project per client. Serverless Framework is perfect for this kind of situation.
However, I can’t seem to figure out how to split multiple Java packages into separate .ZIP files using Java and Gradle.
Snippet out of my serverless.yml file:

  individually: true
    - src/**

    handler: com.serverless.Handler
        - src/main/java/com/serverless/**
      artifact: build/distributions/

    handler: com.tbs.TestClass::handleRequest
        - src/main/java/com/tbs/**
      artifact: build/distributions/

I have tried multiple arrangements of the lines of code, but to no avail. Could someone help point me in the right direction.

Hi @jbvdm ,
If I am not mistaken, then you seem to expect that serverless will take care of building the artifacts.
This, however, is not the case (for Java). You have to build it with gradle and then run serverless deploy.
Serverless will pick up the artifacts (created by gradle) you referenced and deploys them.
So serverless will simply ignore the given include/exclude statements since you or rather gradle built the artifact.

Given that you’ll need to take care of building separate artifacts with certain packages only in gradle.

This might be helpful:

And just my personal opinion: I don’t think it is a good practice to just deploy a portion (certain packages) of a Java project. It might be better to have just one artifact and each function references a different handler i.e. class. Or really have one Java project per function.

1 Like

Hi @bbilger,
Thank you for your advice. It seems intuitive now that you have given me some direction to work towards… We have decoupled our code, so it is in the form of microservices. However, I haven’t thought of still keeping it in different projects inside the Serverless project. Would you suggest this as a good way forward?
The reason for using the Serverless Framework is to keep all our code in on place but still have our functions as microservices. If this is not the best application for this framework would there be another better solution?
I have asked this question on Stackoverflow. Would you mind giving me the same answer so I could accept it as correct(gain some ‘cred’)? link to question