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

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

1 vote

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

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.

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 1 person likes this

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
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

402 views 5 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you