You can attach a shared persistent volume to the build container to speed up the build process and If you are using Jenkins & kubernetes, you should definitely try out the container-based agents. Scaling your jenkins agents on kubernetes helps you from a lot of administrative overhead that you get with static build VMs.
The below information extracted from the document authored by Bibin Wilson might be helpful to you:
For example, if you take a Java application, it has many Maven package dependencies.
When you build the Java apps, it downloads dependencies added in the pom.xml from the remote maven repository the first time, and it creates a local .m2 cache directory where the dependent packages are cached.
The .m2 cache is not possible in Docker agent-based builds as it gets destroyed after the build.
We can create a persistent volume for the maven cache and attach it to the agent pod via the container template to solve this issue.