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

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

我正在尝试发布 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命令后获得的状态之前吗?在以下链接中,我不明白是否必须手动执行某些操作(从 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>

最佳答案

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

<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 部分。部署 Artifact 的一种方法是简单地从 VCS 获取标签并执行 mvn deploy。 ,像这样:

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

关于maven - 在哪里指定 Artifactory 发布的存储库元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34871366/

相关文章:

java - jetty : NoClassDefFoundError

java - 在 pom.xml 中包含 proguard 配置文件

java - teamcity如何自动推送jar到Artifactory

artifactory - 在 JFrog 的 Artifactory 中添加新的远程存储库时出错

java - maven项目中如何定义常用配置

java - 为什么使用 -D 而不是 -P 来激活 Maven 配置文件?

java - 如何将 JSF 扩展库用作 OSGI 包

continuous-integration - 快照和发布存储库的使用方式有何不同?

java - 无法连接到 postgresQL

maven - 构建多个 Maven 模块,然后在 Docker 镜像中复制 JAR