如何解决另一个存储库中存在的 bitbucket 管道中的 maven 依赖项

Sha*_*bry 5 maven bitbucket-pipelines mulesoft

我正在使用 bitbucket-pipelines 为我公司的 mulesoft API 设置部署管道。由于与 Jira 的内置集成,这项技术对我们很有吸引力。问题是我们正在使用域项目。所有其他依赖项都是从 anypoint exchange 下载的,但域项目不能托管在那里,所以我收到这个错误:

[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)
Run Code Online (Sandbox Code Playgroud)

在我们当前的过程中,涉及在本地构建项目,域项目包含在工作区中,不会发生此错误。

似乎这里有一些策略: * 创建一个包含依赖项的自定义 docker 映像 - 这个选项似乎有点过分,对我来说是最大的技能差距,因为我从未使用过 docker。* 将域项目托管在要在依赖项目 pom.xml 中引用的私有 Maven 存储库上 - 这似乎是执行此操作的“正常”方式。然而,对于一个依赖项来说,这似乎又是一种矫枉过正。* 在管道文件中克隆域项目存储库,自动将项目安装在本地存储库中 - 这是我非常喜欢的选项。我已经成功克隆了 repo 并在其根目录中运行 mvn install,但是在下一步运行 mule deploy 时,它仍然找不到依赖项。我不确定管道中的文件结构到底是什么样的,并且不能'

我的 bitbucket-pipelines.yml 文件

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 git@bitbucket.org:[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
Run Code Online (Sandbox Code Playgroud)

我的非域项目的 pom.xml 文件

<?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>

Run Code Online (Sandbox Code Playgroud)

我也在 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>
Run Code Online (Sandbox Code Playgroud)

并得到这个错误

[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

Run Code Online (Sandbox Code Playgroud)

如果不清楚,我已经审查了我公司的名称。

预期的结果是项目成功构建和部署。

小智 2

你可以按照这篇文章来实现它。 云存储库和位桶示例

这是一种方法。对我有用:

  • 添加 settings.xml 文件并更改 bitbucket 安全变量的云存储库用户和密码。
<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>
Run Code Online (Sandbox Code Playgroud)
  • 将这些变量添加到您的 bitbucket 管道中

位桶管道安全变量

  • 将 Maven 步骤添加到您的 bitbucket-pipelines.yml 中,包括setting.xml
image: maven:3.6.1

pipelines:
  default:
    - step:
        caches:
          - maven
        script:
          - mvn -s settings.xml -B verify
Run Code Online (Sandbox Code Playgroud)