Compile a package before deploying

I have a serverless.yml that is getting the right java .jar file to deploy, as specified by the package->artifact. However I’d like to compile the jar immediately before deploying.

Seems like a common use case but I don’t see any documentation about how to do so, other than predeployment processing using Serverless Variables, which seems strangely complicated for a build and deploy tool. What am I missing?

Advice much appreciated!