How to build Java project on existing virtual machine in Azure?
You can use a custom build container image for your pipeline with Maven and all of your other dependencies. You will need to: 


Create a Dockerfile that installs Maven and all other dependencies that you have
Build the image and upload it to a custom Azure Container Registry
Modify your YAML pipeline file to reference the new build image


Sample:

resources:
   containers:
     - container: build_container
       image: demoxyz.azurecr.io/pipeline-build-image:latest
       endpoint: AzureCR
       options: '-v /usr/bin/docker:/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock'


Here is an article that discusses the topic.