【问题标题】:Deploy Maven project to local Artifactory service将 Maven 项目部署到本地 Artifactory 服务
【发布时间】:2015-11-22 20:50:19
【问题描述】:

我有 forked 一个 webjar 项目,用于在我公司的环境中本地工作。我们使用 Artifactory/Ivy 进行依赖管理。

目前 Smart Table(和其他 webjars)pom.xml 显示以下部署:

        <plugin>
            <groupId>org.sonatype.plugins</groupId>
            <artifactId>nexus-staging-maven-plugin</artifactId>
            <version>1.6.5</version>
            <extensions>true</extensions>
            <configuration>
                <serverId>sonatype-nexus-staging</serverId>
                <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                <autoReleaseAfterClose>true</autoReleaseAfterClose>
            </configuration>
        </plugin>

默认情况下,它将发布到 Sonatype,这对于公开可见的开源项目非常有用一旦您拥有发布凭据

但是,我们目前确实希望在项目的一个分支上本地工作并部署到我们的本地 Artifactory 服务器。贡献(对真实项目的)将通过 Pull Request 共享,因此我们对去 Sonatype 存储库不感兴趣。

问题

如何更改 Maven pom.xml 以使 mvn deploy 部署到本地配置的 Artifactory 服务? (当然,凭证存储在 Maven 配置中)

奖金问题

我可以告诉 Maven 使用 Ivy 布局发布我应该在 Artifactory 中创建一个新的 Maven 布局存储库吗?

【问题讨论】:

    标签: maven ivy artifactory webjars


    【解决方案1】:

    第一个选项是使用标准Maven deploy plugin

    <distributionManagement>
        <repository>
          <id>repo-id</id>
          <name>Artifactory</name>
          <url>http://server:8081/artifactory/repo-id</url>
        </repository>
      </distributionManagement>
    

    您应该配置您的 settings.xml 文件以定义提供身份验证信息的相应条目。服务器条目使用它们的元素匹配到 distributionManagement 的不同部分。

    <server>
       <id>repo-id</id>
       <username>repo-username</username>
       <password>password/encrypted password</password>
    </server>
    

    第二个选项是使用 JFrog Maven Artifactory plugin,可在 JCenter 存储库的 Bintray 中获得

    <build>
        <plugins>
            ...
            <plugin>
                <groupId>org.jfrog.buildinfo</groupId>
                <artifactId>artifactory-maven-plugin</artifactId>
                <version>2.4.0</version>
                <inherited>false</inherited>
                <executions>
                    <execution>
                        <id>build-info</id>
                        <goals>
                            <goal>publish</goal>
                        </goals>
                        <configuration>
                            <deployProperties>
                                <gradle>awesome</gradle>
                                <review.team>qa</review.team>
                            </deployProperties>
                            <publisher>
                                <contextUrl>https://server:8081/artifactory</contextUrl>
                                <username>username</username>
                                <password>{DESede}...</password>
                                <repoKey>libs-release-local</repoKey>
                                <snapshotRepoKey>libs-snapshot-local</snapshotRepoKey>
                            </publisher>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    

    通过 Maven Artifactory 插件,Artifactory 与 Maven 构建完全集成,并允许您执行以下操作:

    1. 将属性附加到 Artifactory 元数据中已发布的工件。
    2. 捕获可以传递给 Artifactory REST API 以提供完全可跟踪的构建上下文的 BuildInfo 对象。
    3. 在构建结束时自动发布所有构建工件。

    更详细的插件使用示例可以在Github project找到。

    额外问题

    Maven 只能部署到 Maven2(默认)或 Maven1(旧版)布局存储库。您必须在 Artifactory 中创建一个新的 Maven 存储库。

    【讨论】:

      猜你喜欢
      • 2015-10-20
      • 1970-01-01
      • 2019-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多