【问题标题】:Where to specify the repository element for Artifactory release?在哪里为 Artifactory 版本指定存储库元素?
【发布时间】:2016-04-24 14:32:54
【问题描述】:

我正在尝试在 Artifactory 存储库中发布一个项目。这是一个项目,它是我的主项目的依赖项,所以我想将 pom、.jar 和 sources.jar 放在工件存储库中。

settings.xml文件存放在maven目录下:

D:\...\...\maven\apache-maven-3.3.1\conf  

我已经使用以下 maven 命令标记了版本:

mvn clean release:prepare  

那么,如果我尝试:

mvn clean release:perform –Partifactory  

,我得到了错误:

[INFO] [ERROR] 无法在项目上执行目标 org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) ......:部署失败:存储库元素未在 distributionManagement 元素内的 POM 或 -DaltDeploymentRepository=id::layout::url 参数中指定

我应该怎么做才能使用工件配置文件?是否可以不更改 pom ? 我尝试将 settings.xml 复制到我的本地 Maven 存储库中,但没有成功。

如果我必须更改pom,我可以先回到mvn release:prepare命令之后获得的状态之前吗?在以下链接中,我不明白是否必须手动执行某些操作(从 SCM 中删除标签): http://maven.apache.org/maven-release/maven-release-plugin/examples/rollback-release.html

settings.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<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  http://maven.apache.org/xsd/settings-1.0.0.xsd">

<localRepository>D:\...\...\maven\repository</localRepository>

<profiles>  
<profile>  
  <repositories>  
    <repository>  
      <snapshots>  
        <enabled>false</enabled>  
      </snapshots>  
      <id>central</id>  
      <name>libs-release</name>  
      <url>http://x/artifactory/libs-release</url>  
    </repository>  
    <repository>  
      <snapshots />  
      <id>snapshots</id>  
      <name>libs-snapshot</name>  
      <url>http://x/artifactory/libs-snapshot</url>  
    </repository>  
  </repositories>  
  <pluginRepositories>  
    <pluginRepository>  
      <snapshots>  
        <enabled>false</enabled>  
      </snapshots>  
      <id>central</id>  
      <name>plugins-release</name>  
      <url>http://x/artifactory/plugins-release</url>  
    </pluginRepository>  
    <pluginRepository>  
      <snapshots />  
      <id>snapshots</id>  
      <name>plugins-snapshot</name>  
      <url>http://x/artifactory/plugins-snapshot</url>  
    </pluginRepository>  
  </pluginRepositories>  
  <id>artifactory</id>  
</profile>  
  </profiles>  
  <activeProfiles>  
   <activeProfile>artifactory</activeProfile>  
  </activeProfiles>  

</settings> 

pom:

<?xml version="1.0" encoding="UTF-8"?>
<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">

    <parent>
        <groupId>....</groupId>
        <artifactId>my-parent</artifactId>
        <version>1.0.6</version>
        <relativePath />
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <groupId>....</groupId>
    <artifactId>myproject</artifactId>
    <packaging>jar</packaging>
    <version>1.9.6-SNAPSHOT</version>
    <name>myproject</name>
    <url>${wiki.url}</url>
    <scm>    <developerConnection>scm:svn:http://x/svn/main/y/Development/Components/trunk/myproject</developerConnection>
        <url>http://x/svn/main/y/Development/Components/trunk/myproject</url>
    </scm>
    <ciManagement>
        <system>${ciManagement.system}</system>
        <url>${ciManagement.url}/${project.artifactId}</url>        
    </ciManagement>

    <properties>       
    </properties>

    <dependencies>
        <! -  - my dependencies -  - >
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <inherited>false</inherited>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>   <tagBase>http://x/svn/main/y/Development/Components/tags</tagBase>
                </configuration>
            </plugin>
        </plugins>
    </build>

    </project>

The parent pom :  

<!-- language: lang-xml -->

    <?xml version="1.0" encoding="UTF-8"?>
    <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>....</groupId>
    <artifactId>my-parent</artifactId>
    <packaging>pom</packaging>
    <version>1.0.6</version>
    <name>my-parent</name>
    <url>${wiki.url}</url>
    <scm>
        <developerConnection>scm:svn:http://x/svn/main/y/Development/Components/tags/my-parent-1.0.6</developerConnection>
        <url>http://x/svn/main/y/Development/Components/tags/my-parent-1.0.6</url>
    </scm>
    <ciManagement>
        <system>${ciManagement.system}</system>
        <url>${ciManagement.url}/${project.artifactId}</url>        
    </ciManagement>
    <build> 
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <inherited>true</inherited>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.3</version>
            </plugin>

        </plugins>
    </build>

</project>

【问题讨论】:

    标签: maven pom.xml artifactory maven-release-plugin


    【解决方案1】:

    两件事。你应该在你的 POM 中声明一个&lt;distributionManagement&gt; 部分:

    <project>
      ...
      <distributionManagement>
        <repository>
         <id>my-artifactory</id>
         <name>Artifactory Release Repo</name>
         <url>http://x/artifactory/libs-release</url>
        </repository>
        <snapshotRepository>
         <id>my-artifactory</id>
         <name>Artifactory Release Repo</name>
         <url>http://x/artifactory/libs-snapshot</url>
        </snapshotRepository>
      </distributionManagement>
    </project>
    

    &lt;id&gt; 标记必须与您的 settings.xml 中的条目匹配,凭据才能匹配:

    <settings>
      ...
      <servers>
       <server>
        <id>my-artifactory</id>
        <username>bob</username>
        <password>secret</password>
       </server>
      </servers>
    </settings>
    

    现在,话虽如此,由于 mvn release:prepare 已经在您的 VCS 中标记了该版本,您不需要 删除新版本,但我建议您添加 @987654329 @ 部分到 POM。部署工件的一种方法是简单地从 VCS 获取标签并执行mvn deploy,如下所示:

    svn co <the url to your tag>
    mvn -DaltDeploymentRepository=my-artifactory::default::http://x/artifactory/libs-release deploy
    

    【讨论】:

    • 感谢您的回答。实际上我不明白 mvn deploy 和 mvn release:perform 之间的区别。他们是否都将项目复制到远程存储库?他们中的一个会做更多的事情吗?第二个问题:如果它们已经存在于 pom 中,那么 settings.xml 中的存储库信息有什么用?
    • 好吧,mvn deploy 这样做:部署工件。 release:performrelease:prepare 离开的地方继续。通过使用来自release:prepare 阶段的release.properties 文件中的信息,release:perform 实际上将根据您的设置从release:preparedeploy 期间创建的标签中进行检查。
    • 因此,如果在 pom 中定义了所有工件(pom、sources.jar、jar、javadoc.jar、war),这两个命令都会部署它们?
    • 是的,但是 release 插件将转换 POM、标记、提交、推送(用于 git)等。此外,两者都需要 &lt;distributionManagement&gt; 部分来部署。
    • 我尝试了您推荐的更改:无法在项目 myproject 上执行目标 org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy):无法检索远程元数据...:myproject:1.9.6-SNAPSHOT/maven-metadata.xml:无法传输元数据...:myproject:1.9.6-SNAPSHOT/maven-metadata.xml 从/到 my-artifactory (x/artifactory/libs-release) : 传输文件失败:x/artifactory/libs-release... /myproject /1.9.6-SNAPSHOT/maven-metadata.xml。返回码是:502,ReasonPhrase:Proxy Error。您认为这是工件的用户/密码问题吗?
    猜你喜欢
    • 1970-01-01
    • 2012-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多