在哪里指定 Artifactory 发布的存储库元素?

Where to specify the repository element for Artifactory release?

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

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

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

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

mvn clean release:prepare  

然后,如果我尝试:

mvn clean release:perform –Partifactory  

,我收到错误:

[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project ........ : Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter

我应该如何使用神器配置文件?不改变 pom 可能吗? 我尝试在我的本地 Maven 存储库中复制 settings.xml 但没有成功。

如果一定要改pom,可以先返回到mvn release:prepare命令后得到的state之前吗?在下面的link中,我不明白是否必须手动执行某些操作(从 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>

两件事。您应该在 POM 中声明一个 <distributionManagement> 部分:

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

<id> 标签必须与您的 settings.xml 中的条目匹配才能匹配凭据:

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

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

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