maven返回码是:409,ReasonPhrase:冲突

时间:2019-07-23 09:08:33

标签: maven deployment

我在部署具有以下结构的多模块python项目时遇到问题

parent pom.xml # common pom for others project
project/ 
   pom.xml # project pom
   common_features/
        sub-project-1/pom.xml # sub project 1 pom
        sub-project-2/pom.xml # sub project 2 pom

对于部署,我使用maven

Settings.xml

常规Maven设置用于构建

<?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">
  <!-- others options -->
  <servers>
    <server>
      <id>artifacts-SNAPSHOTS</id>
      <username>user</username>
      <password>password</password>
    </server>
   </servers>
  <!-- others options -->
</settings>

父pom.xml

在这种情况下,我们为SNAPSHOT和RELEASE存储库使用相同的URL

<!-- others options -->
<groupId>com.project.common.group.id</groupId>
<artifactId>project-pom</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>

<!-- others options -->
<distributionManagement>
    <repository>
        <id>artifacts-RELEASES</id>
        <url>${dist.repository.releases}</url>
    </repository>
    <snapshotRepository>
        <id>artifacts-SNAPSHOTS</id>
        <url>${dist.repository.snapshots}</url>
    </snapshotRepository>
</distributionManagement>

<!-- others sections-->
<properties>
    <dist.repository.releases>${artifacts.repository.url}</dist.repository.releases>
    <dist.repository.snapshots>${artifacts.repository.url}</dist.repository.snapshots>
    <artifacts.repository.url>https://domain/artifactory/mvn-repo-dev</artifacts.repository.url>
</properties>

项目pom.xml

您可以看到项目包含两个模块

  • sub-project-1
  • sub-project-2

父母是普通父母。 我也起诉maven程序集插件,以便将项目部署到工件中

<!-- anothers options -->
<parent>
    <groupId>com.project.common.group.id</groupId>
    <artifactId>project-pom</artifactId>
    <version>0.0.1</version>
</parent>

<groupId>com.project.group.id</groupId>
<artifactId>project-pom</artifactId>
<version>1.0.0-SNAPSHOT</version>

<packaging>pom</packaging>

<modules>
    <module>common_features/sub-project-1</module>
    <module>common_features/sub-project-2</module>
</modules>

build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <appendAssemblyId>false</appendAssemblyId>
                <descriptors>
                    <descriptor>deploy/artifact-description.xml</descriptor>
                </descriptors>
                <tarLongFileMode>posix</tarLongFileMode>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <phase>package</phase>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.jfrog.buildinfo</groupId>
            <artifactId>artifactory-maven-plugin</artifactId>
            <version>2.6.1</version>
            <inherited>false</inherited>
            <executions>
                <execution>
                    <id>build-info</id>
                    <goals>
                        <goal>publish</goal>
                    </goals>
                    <configuration>
                        <publisher>
                            <contextUrl>https://domain/artifactory</contextUrl>
                            <repoKey>mvn-repo-dev</repoKey>
                            <snapshotRepoKey>mvn-repo-dev</snapshotRepoKey>
                            <publishArtifacts>true</publishArtifacts>
                            <publishBuildInfo>true</publishBuildInfo>
                            <username>deployUser</username>
                            <password>deployPwd</password>
                        </publisher>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
   

artifact-description.xml

我只希望部署某些部分,因此我定义了以下部署文件。这样,我确保将仅将常见功能和项目特定的脚本/代码部署到软件包中

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-    plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
    <id>${distributionId}</id>
    <formats>
        <format>tar.gz</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <outputDirectory>project/${subProjectName}/</outputDirectory>
            <directory>${basedir}/..</directory>
            <fileMode>0755</fileMode>
            <lineEnding>unix</lineEnding>
            <includes>
                <include>/*.*</include>
                <include>/sub-${subProjectName}/*</include>
            </includes>
            <excludes>
                <exclude>**/*.pyc</exclude>
                <exclude>**/*.xls</exclude>
                <exclude>**/*.xlsx</exclude>
                <exclude>**/pom.xml</exclude>
                <exclude>**/target</exclude>
                <exclude>**/deploy</exclude>
                <exclude>**/.venv</exclude>
            </excludes>
        </fileSet>
    </fileSets>
</assembly>

sub-project-1 pom.xml

这只是简单的pom,没有其他插件和构建选项

<parent>
    <groupId>com.project.group.id</groupId>
    <artifactId>project-pom</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <relativePath>../../pom.xml</relativePath>
</parent>

<packaging>pom</packaging>
<groupId>com.project.group.id</groupId>
<artifactId>sub-project-1</artifactId>
<version>1.0.0-SNAPSHOT</version>

<properties>
    <subProjectName>project-1</subProjectName>
</properties>

sub-project-2 pom.xml

与sub-project-1相同的pom.xml

<parent>
    <groupId>com.project.group.id</groupId>
    <artifactId>project-pom</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <relativePath>../../pom.xml</relativePath>
</parent>

<packaging>pom</packaging>
<groupId>com.project.group.id</groupId>
<artifactId>sub-project-2</artifactId>
<version>1.0.0-SNAPSHOT</version>

<properties>
    <subProjectName>project-2</subProjectName>
</properties>

现在我只想将sub-project-1生成并上传到工件中,因此我将使用以下maven命令:

mvn -e -B -U -X clean deploy --projects :sub-project-1 -DskipIntegrationTests=false -DskipCoverageReport=false

但是随后发生以下错误:

Caused by: org.apache.maven.wagon.TransferFailedException: Failed to transfer file: https://domain/artifactory/mvn-repo-dev/com/project/group/id/project/project-1/1.0.0-SNAPSHOT/sub-project-1-1.0.0-20190723.081454-1.pom. Return code is: 409, ReasonPhrase: Conflict.
    at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:627)
    at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:541)
    at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:523)
    at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:517)
    at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:497)
    at org.eclipse.aether.transport.wagon.WagonTransporter$PutTaskRunner.run(WagonTransporter.java:644)
    at org.eclipse.aether.transport.wagon.WagonTransporter.execute(WagonTransporter.java:427)
    at org.eclipse.aether.transport.wagon.WagonTransporter.put(WagonTransporter.java:410)
    at org.eclipse.aether.connector.basic.BasicRepositoryConnector$PutTaskRunner.runTask(BasicRepositoryConnector.java:510)
    at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run(BasicRepositoryConnector.java:350)
    ... 32 more

现在我不确定出什么问题了,我花费了大量时间调查此问题,但没有发现任何问题。请问您有什么建议吗?非常感谢

1 个答案:

答案 0 :(得分:0)

我发现问题出在哪里。在父pom.xml中,有以下插件可以更改artifactId。我不知道为什么会收到错误409,但最终这是一个原因:

        <plugin>
            <groupId>org.codehaus.groovy.maven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>pre-clean</phase>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <source>
                            project.getModel().setArtifactId(project.properties["someProperty"].replaceAll('_',
                            '-'))
                            project.getArtifact().setArtifactId(project.properties["someProperty"].replaceAll('_',
                            '-'))
                        </source>
                    </configuration>
                </execution>
            </executions>
        </plugin>