Java with Bitbucket Pipelines
Here's how you can configure the bitbucket-pipelines.yml file to build and test a Java project, using either Maven or Gradle as your build tool.
Building and testing Maven projects
Specify your Maven version with Docker
Bitbucket Pipelines runs all your builds in Docker containers using an image that you specify at the beginning of your configuration file. You can easily use Maven with Bitbucket Pipelines by using one of the official Maven Docker images on Docker Hub.
For instance, you can use Maven 3.3.9 (current version as of writing) by specifying it at the beginning of your bitbucket-pipelines.yml file.
Java and JDK versions
By default, the Maven image will include a recent official version of the Java JDK, but you can specify a different version instead by using a specific Maven version. Below is an example using the Docker image for Maven 3.2.5 with JDK 1.7.
You can find a list of available Maven/JDK versions and corresponding image tags, refer to https://hub.docker.com/r/library/maven/.
Building and running tests with Maven
Once you have selected your Docker image, running tests is just including the appropriate Maven commands in your Pipelines script. Here's a simple example.
Private Maven repositories
To access a private Maven repository, you'll need to override the default Maven
settings.xml found in the Docker image at
Custom Maven settings.xml
Making more advanced changes to the default settings.xml with sed can be quite painful, so it may be easier to commit your own settings.xml to your Bitbucket repository. Then you can reference it using Maven's
Building and testing Gradle projects
Was this helpful?
Thanks for your feedback!