I'm setting up a deployment pipeline for my companys mulesoft APIs using bitbucket-pipelines. This technology is attractive to us because of the built in integrations with Jira. The problem is that we are using a domain project. All of the other dependencies get downloaded from anypoint exchange, but the domain project cannot be hosted there, so I get this error:
[ERROR] Failed to execute goal on project sourceControlDemo: Could not resolve dependencies for project com.mycompany:sourceControlDemo:mule-application:1.0.0-SNAPSHOT: Could not find artifact com.mycompany:[mycompany]-domain:jar:mule-domain:1.0.0 in anypoint-exchange (https://maven.anypoint.mulesoft.com/api/v1/maven) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project sourceControlDemo: Could not resolve dependencies for project com.mycompany:sourceControlDemo:mule-application:1.0.0-SNAPSHOT: Could not find artifact com.mycompany:[mycompany]-domain:jar:mule-domain:1.0.0 in anypoint-exchange (https://maven.anypoint.mulesoft.com/api/v1/maven)
In our current process, which involves building the projects locally, the domain project is included in the workspace and this error does not occur.
It seems as though there are a few strategies here: * Create a custom docker image with the dependency included - This options seems overkill, and presents the biggest skill gap for me, as I have never used docker. * Host the domain project on a private maven repo to be referenced in the dependent project pom.xml - This seems like the "normal" way to do it. However, it again seems like overkill for one dependency. * Clone the domain project repo in the pipeline file, install the project in the local repository automatically - this is the option I'd really like to go with. I've managed to clone the repo and run mvn install in its root, but upon running mule deploy in the next step, it still cannot find the dependency. I'm not sure what the file structure really looks like in the pipeline, and can't figure out how to configure the pom to look in the right place.
My bitbucket-pipelines.yml file
image: maven:3.6.1-jdk-8
pipelines:
branches:
DEV:
- step:
name: install domain project
trigger: automatic
caches:
- maven
script:
- apt-get update -y
- apt-get install -y git
- cd ..
- git clone [email protected]:[mycompany]/[mycompany]-domain.git
- cd [mycompany]-domain
- mvn install
- cd ../build
- step:
name: Build and Deploy
trigger: automatic
caches:
- maven
deployment: DEV
script:
- mvn deploy -e -DmuleDeploy
My pom.xml file for the non domain project
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>sourceControlDemo</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>mule-application</packaging>
<name>sourceControlDemo</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<app.runtime>4.1.5</app.runtime>
<mule.maven.plugin.version>3.2.7</mule.maven.plugin.version>
</properties>
<build>
<finalName>${artifactId}-${BITBUCKET_BUILD_NUMBER}</finalName>
<plugins>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<armDeployment>
<uri>https://anypoint.mulesoft.com</uri>
<target>${target}</target>
<targetType>${target_type}</targetType>
<username>${username}</username>
<password>${password}</password>
<environment>${environment}</environment>
<muleVersion>4.1.5</muleVersion>
</armDeployment>
</configuration>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>[mycompany]-domain</artifactId>
<version>1.0.0</version>
<classifier>mule-domain</classifier>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>anypoint-exchange</id>
<name>Anypoint Exchange</name>
<url>https://maven.anypoint.mulesoft.com/api/v1/maven</url>
<layout>default</layout>
</repository>
<repository>
<id>mulesoft-releases</id>
<name>MuleSoft Releases Repository</name>
<url>https://repository.mulesoft.org/releases/</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>mulesoft-releases</id>
<name>mulesoft release repository</name>
<layout>default</layout>
<url>https://repository.mulesoft.org/releases/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
I've also tried this in the pom:
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>[mycompany]-domain</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<type>jar</type>
<classifier>mule-domain</classifier>
<systemPath>${basepath}/.m2/repository</systemPath>
</dependency>
and got this error
[ERROR] Failed to execute goal on project sourceControlDemo: Could not resolve dependencies for project com.mycompany:sourceControlDemo:mule-application:1.0.0-SNAPSHOT: Could not find artifact com.mycompany:[mycompany]-domain:jar:mule-domain:1.0.0 at specified path /root/.m2/repository -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project sourceControlDemo: Could not resolve dependencies for project com.mycompany:sourceControlDemo:mule-application:1.0.0-SNAPSHOT: Could not find artifact com.mycompany:[mycompany]-domain:jar:mule-domain:1.0.0 at specified path /root/.m2/repository
In case it's not clear, I've censored my company's name.
The expected result is for the project to successfully build and deploy.
Description: Goal that resolves the project dependencies from the repository. When using this goal while running on Java 9 the module names will be visible as well.
When you run the Maven release plugin (ie. mvn release:prepare release:perform), maven will create git commits and attempt to push them back to your source code repository. A Bitbucket Pipeline does not have the permissions to push to a repository so we have to enable this by adding an SSH key associated with a Pipeline.
Bitbucket Pipelines runs your builds in a Docker container that provides the build environment. There are a few ways you can specify any dependencies that your build needs in that container – we recommend running dependencies as services in their own containers.
Bitbucket is not a maven repository. You should use such repositories as Nexus, Artifactory and so on. You must be a registered user to add a comment.
A Bitbucket Pipeline does not have the permissions to push to a repository so we have to enable this by adding an SSH key associated with a Pipeline. We need a key pair to allow Pipelines to git push back to this repo when we are releasing an artifact via a mvn release:perform command.
You can follow this article, to achieve it. cloud-repo-and-bitbucket-example
Here is one way to do it. Works for me:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd"
<!-- Complete Documentation for the settings.xml file can be found at https://maven.apache.org/settings.html -->
<activeProfiles>
<activeProfile>example</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>example</id>
<repositories>
<repository>
<id>${private_repo_id}</id>
<name>Example Java Repository</name>
<url>${private_repo_url}</url>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>io.cloudrepo</id>
<username>${prived_user_repo}</username>
<password>${prived_password_repo}</password>
</server>
</servers>
</settings>
image: maven:3.6.1
pipelines:
default:
- step:
caches:
- maven
script:
- mvn -s settings.xml -B verify
This following works when an external repository is not the preferred approach.
Create a key pair in the repository which should consume the other dependency (the main project): https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/
Add the public key as access key to the projects which is the dependency (the dependency): https://confluence.atlassian.com/bitbucket/use-access-keys-294486051.html
Configure the build pipeline based on the maven Docker image (adjust to the latest version provided by Bit Bucket). Pay attention to the first step, which is not executed in parallel building the necessary dependency before the main project is built.
image: maven:3.6.3
pipelines:
default:
- step:
name: Build Local Dependencies
caches:
- maven
script:
- git clone [email protected]:<user>/<project>.git
- cd <project>
- mvn clean install
- cd ..
- parallel:
- step:
name: Build and Test
caches:
- maven
script:
- mvn -B verify --file pom.xml
after-script:
# Collect checkstyle results, if any, and convert to Bitbucket Code Insights.
- pipe: atlassian/checkstyle-report:0.3.0
- step:
name: Security Scan
script:
# Run a security scan for sensitive data.
# See more security tools at https://bitbucket.org/product/features/pipelines/integrations?&category=security
- pipe: atlassian/git-secrets-scan:0.5.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With