简体   繁体   English

将Maven项目部署到本地Artifactory服务

[英]Deploy Maven project to local Artifactory service

I have forked a webjar project for working locally in my company's environment. 我已经分叉一个webjar项目在我公司的环境中本地工作。 We use Artifactory/Ivy for dependency management. 我们使用Artifactory / Ivy进行依赖管理。

Currently Smart Table (and other webjars) pom.xml show the following for deployment: 当前,智能表(和其他Webjar) 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>

It will by default publish to Sonatype, which is good for publicly-visible open source projects once you have release credentials . 默认情况下,它将发布到Sonatype, 一旦您具有发行凭据 ,它就对公开可见的开源项目很有用

However we do currently want to work locally on a fork of the project and deploy to our local Artifactory server. 但是,我们目前确实希望在项目的分支上进行本地工作,并部署到我们的本地 Artifactory服务器。 Contributions (to the real project) will be shared via Pull Request, so we are not interested in going to Sonatype repository. (对真实项目的贡献)将通过Pull Request共享,因此我们对转到Sonatype存储库不感兴趣。

Question

How do I change Maven pom.xml so that mvn deploy will deploy to a locally-configured Artifactory service? 如何更改Maven pom.xml,以便将mvn deploy部署到本地配置的Artifactory服务? (For which credentials are stored in Maven configuration of course) (当然,凭据存储在Maven配置中)

Bonus question 奖金问题

Can I tell Maven to publish using Ivy layout or should I create a new Maven-layout repository in Artifactory? 我可以告诉Maven使用Ivy布局发布, 还是应该在Artifactory中创建一个新的Maven-layout存储库?

First option is to use the standard Maven deploy plugin 第一种选择是使用标准的Maven部署插件

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

You should configure your settings.xml file to define corresponding entries which provides authentication information. 您应该配置settings.xml文件以定义提供身份验证信息的相应条目。 Server entries are matched to the different parts of the distributionManagement using their elements. 服务器条目使用其元素匹配到distributionManagement的不同部分。

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

Second option is to use the JFrog Maven Artifactory plugin , available at the JCenter repository in Bintray 第二种选择是使用JFrog Maven Artifactory插件 ,该插件可在Bintray的JCenter存储库中获得。

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

Through the Maven Artifactory Plugin, Artifactory is fully integrated with Maven builds and allows you to do the following: 通过Maven Artifactory插件,Artifactory与Maven构建完全集成,并允许您执行以下操作:

  1. Attach properties to published artifacts in Artifactory metadata. 将属性附加到Artifactory元数据中已发布的工件。
  2. Capture a BuildInfo object which can be passed to the Artifactory REST API to provide a fully traceable build context. 捕获一个BuildInfo对象,该对象可以传递给Artifactory REST API以提供完全可追溯的构建上下文。
  3. Automatically publish all build artifacts at the end of the build. 在构建结束时自动发布所有构建工件。

More detailed usage examples of the plugin can be found in this Github project . 可以在此Github项目中找到该插件的更多详细用法示例。

Bonus question 奖金问题

Maven can only deploy to a Maven2 (default) or Maven1 (legacy) layout repository. Maven只能部署到Maven2(默认)或Maven1(传统)布局存储库。 You will have to create a new Maven repository in Artifactory. 您将必须在Artifactory中创建一个新的Maven存储库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM