Pipeline - build depends on another development package in a different repo

Patrick Farren December 21, 2017

How do i setup and build a dependency maven package within a pipeline.

Issue:

I would like to create a pipeline to build(maven) a new java app package but this package depends on another 'common' package held in a different bitbucket repo.

Within my local development environment the build process is straightforward 

step 1. within common package folder run : mvn clean install

step 2. within the new java app package run : mvn clean package

This successfully places the common jar file into local maven repo and is available during the build of the new java app.

Question:

How do I perform similar steps in a pipeline? Do I assume that I will have a local maven repo in the docker image during the build pocess?

 

Thanks for your help

1 answer

2 votes
Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 27, 2017

Hi Patrick,

I have two possible solutions for you here.

--------------

First option. If you want to replicate what you are doing on your own machine, you will need to clone the common package into your pipeline as well. As we will only clone the main java application repository.

You'll need to set up access keys and ssh keys for your repository and pipelines:

You'll then want something like the following in your bitbucket-pipelines.yml for your main java repository:

image: java:8
pipelines:
default:
step:
- apt-get update -y
- apt-get install -y git
- git clone git@bitbucket.org:username/common.git
- cd common
- mvn clean install
- cd ..
- mvn clean package
- # Whatever else you need.

--------------

Second option. If you want a more idiomatic pipeline, you can instead have two pipelines. One to build you common package and one to build you main java repository.

You will need to configure your common package to have the maven release plugin: http://maven.apache.org/maven-release/maven-release-plugin/

This will allow you to release the common package as its own package, which you can then use as a regular dependency in your main java repository.

In your common package, once configured in the pom.xml properly, your pipeline should look like:

image: java:8
pipelines:
default:
step:
- mvn clean package
- mvn release:prepare
- mvn release:perform

And then in your main java application repository, your pipeline will simply look like

image: java:8
pipelines:
default:
step:
- mvn clean package
- # Whatever else you need.

Hope this helps!

Thanks,

Phil

Jahz October 7, 2018

Hello, solution 1 works, but adds the overhead to rebuild common each time we want to build a repo which depends on it. But it works so thanks for that.

For solution 2, I don't manage to make it work, but more importantly I don't understand how it could work. When building main app, from where is the common dependency going to be "downloaded" ? I don't see how using the release plugin is putting the common stuff anywhere usable by the main app.

Francisco José Martínez Páez December 4, 2018

For solution 2 this is what you have to do for configuring properly the maven release plugin:

 

Add to the pom:

 

<build>

<plugins>

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

</plugin>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-release-plugin</artifactId>

<version>2.5.3</version>

<configuration>

<tagNameFormat>@{project.version}</tagNameFormat>

<autoVersionSubmodules>true</autoVersionSubmodules>

<releaseProfiles>releases</releaseProfiles>

<checkModificationExcludes>

<checkModificationExclude>pom.xml</checkModificationExclude>

</checkModificationExcludes>

</configuration>

</plugin>

</plugins>

</build>

 

<repositories>

<repository>

<id>Central</id>

<name>Central</name>

<url>http://repo1.maven.org/maven2/</url>

<layout>default</layout>

</repository>

<repository>

<id>spring-milestones</id>

<name>Spring Milestones</name>

<url>https://repo.spring.io/milestone</url>

<snapshots>

<enabled>false</enabled>

</snapshots>

</repository>

<repository>

<id>myMavenRepo.read</id>

            <url>https://mymavenrepo.com/repo/XXXXXXXXXX/</url>

</repository>

</repositories>

 

<scm>

<connection>scm:git:git@bitbucket.org:user/repo</connection>

<developerConnection>scm:git:git@bitbucket.org:user/repo.git</developerConnection>

<url>https://bitbucket.org/franmp911/user/repo.git</url>

<tag>HEAD</tag>

</scm>

 

<distributionManagement>

<repository>

<id>myMavenRepo.write</id>

            <url>https://mymavenrepo.com/repo/YYYYYYYYYY/</url>

</repository>

</distributionManagement>

 

and the pipeline for your common project should be:

 

image: maven:3.3.9

pipelines:

  default:

    - step:

        caches:

          - maven

        script:

          - mvn -B clean deploy

 

for the other project you can do mvn clean install only

Like Jahz likes this
Jahz December 4, 2018

Ok thanks, I understand better now, so basically the common artifact once built will be stored in mymavenrepo.com or any equivalent service, and then when building the main, it'll simply download the dependency from there.

I guess this works as well for private repos for which you don't want your artifacts to be exposed publicly.

As for my own use case, I ended up cutting the dependency between my two repos to make it simpler.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events