6

内部 nexus リポジトリにデプロイするプロジェクトを設定しようとしているときに、現在問題が発生しています。私は一般的にMavenに慣れていないので、ディストリビューション管理の設定方法について、私が本当に理解していないことがあると思います。

基本的な問題は、「mvn deploy」を実行すると、アーティファクトがスナップショット リポジトリに正常にデプロイされているのに、Maven がリリース リポジトリにデプロイしようとして失敗しているということです。現在の構成についての私の理解では、それをリリース リポジトリにも展開するべきではないということです。

以下にさまざまな構成要素を含めましたが、スナップショット ビルドのみが定義され、リリース ビルドのみが定義されるように、プロファイルを使用してセクションを実際に管理する必要があるかどうか疑問に思っています。

これに関するヘルプ/説明は非常に高く評価されます。

配布管理用にPOMに次のものがあります。

<distributionManagement>
<repository>
  <id>internal-releases</id>
  <name>Internal Releases</name>
  <url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
  <id>internal-snapshots</id>
  <name>Internal Snapshots</name>
  <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>

POM の他の場所では、これらのリポジトリを使用してアーティファクトを取得できるように、次のように設定しています。

<repositories>
<repository>
  <id>internal-releases</id>
  <url>http://localhost:8081/nexus/content/repositories/releases</url>
  <snapshots><enabled>false</enabled></snapshots>
</repository>
<repository>
  <id>internal-snapshots</id>
  <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
  <snapshots><enabled>true</enabled></snapshots>
</repository>
<!-- other repos, etc, etc -->
</repositories>

自分のコンピューターで実行されているこのテスト ネクサス インスタンスに発行できる資格情報を提供するために、settings.xml に正しい設定があり、実際にスナップショットを正常にデプロイしています。

問題は、スナップショットを許可しないように構成されているリリース リポジトリにもスナップショットをデプロイしようとすることです。

「mvn deploy」からの出力には、次のものが含まれます。

[INFO] [deploy:deploy {execution: default-deploy}]
[INFO] Retrieving previous build number from internal-snapshots
Uploading: http://localhost:8081/nexus/content/repositories/snapshots/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-8.war
405K uploaded  (service-1.0.0-20101104.170338-8.war)
[INFO] Retrieving previous metadata from internal-snapshots
[INFO] Uploading repository metadata for: 'snapshot com.internal:service:1.0.0-SNAPSHOT'
[INFO] Retrieving previous metadata from internal-snapshots
[INFO] Uploading repository metadata for: 'artifact com.internal:service'
[INFO] Uploading project information for service 1.0.0-20101104.170338-8
[INFO] [deploy:deploy-file {execution: default}]
[INFO] Retrieving previous build number from remote-repository
[INFO] repository metadata for: 'snapshot com.internal:service:1.0.0-SNAPSHOT' could not be found on repository: remote-repository, so will be created
Uploading: http://localhost:8081/nexus/content/repositories/releases/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error deploying artifact: Failed to transfer file: http://localhost:8081/nexus/content/repositories/releases/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar. Return code is: 400

Nexus からのログには、次のものが含まれています (期待どおりです)。

jvm 1    | 2010-11-04 13:03:39 INFO  [p-759477796-118] - o.s.n.p.m.m.M2Repos~          - Storing of item releases:/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar is forbidden by Maven Repository policy. Because releases is a RELEASE repository
jvm 1    | 2010-11-04 13:03:39 ERROR [p-759477796-118] - o.s.n.r.ContentPlex~          - Got exception during processing request "PUT http://localhost:8081/nexus/content/repositories/releases/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar": Storing of item releases:/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar is forbidden by Maven Repository policy. Because releases is a RELEASE repository
4

3 に答える 3

9
  1. pomで次のプロパティを定義します

    <deployFileUrl>${project.distributionManagement.snapshotRepository.url}</deployFileUrl>
    
  2. 次のように maven-deploy-plugin の構成を変更します。

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.5</version>
        <configuration>
            <skip>true</skip>
        </configuration>
        <executions>
            <execution>
                <phase>deploy</phase>
                <configuration>
                    <packaging>jar</packaging>
                    <generatePom>true</generatePom>
                    <url>${deployFileUrl}</url>
                    <artifactId>${project.artifactId}</artifactId>
                    <groupId>${project.groupId}</groupId>
                    <version>${project.version}</version>
                    <file>${project.build.directory}/${project.build.finalName}.jar</file>
                </configuration>
                <goals>
                    <goal>deploy-file</goal>
                </goals>
            </execution>
         </executions>
     </plugin>
    
  3. 次のプロファイルを追加して、 deployFileUrl プロパティにリポジトリ URL を設定します。

    <profiles>
        <profile>
            <id>release-mode</id>
            <properties>
                <deployFileUrl>${project.distributionManagement.repository.url}</deployFileUrl>
            </properties>
        </profile>
    </profiles>
    
  4. 最後にこのプロファイルを maven-release-plugin で呼び出します

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <version>2.0-beta-9</version>
        <configuration>
            <releaseProfiles>release-mode</releaseProfiles>
        </configuration>
     </plugin>
    
于 2012-09-13T19:28:52.143 に答える
5

そのため、最良の手がかりは、ログの目の前にあることが判明しました。私が使用していた POM によって生成されたと私が考えていた唯一の成果物は .war でしたが、Maven がリリースにデプロイしようとしている成果物が実際には .jar であることがログでわかります。

これは (Maven ユーザー メーリング リストの誰かが提供したと指摘した) を探すのに十分な指針であり、最終的に誰かがデプロイ フェーズ用に次の追加の構成を含めていることを発見しました。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
  <phase>deploy</phase>
    <goals>
      <goal>deploy-file</goal>
    </goals>
    <configuration>
      <packaging>jar</packaging>
      <generatePom>true</generatePom>
      <url>${project.distributionManagement.repository.url}</url>
      <artifactId>${project.artifactId}</artifactId>
      <groupId>${project.groupId}</groupId>
      <version>${project.version}</version>
      <file>${project.build.directory}/${project.build.finalName}.jar</file>
    </configuration>
  </execution>
</executions>
</plugin>

これは実際には を直接参照していることに注意してください${project.distributionManagement.repository.url}。また、この構成はやや誤った方向に導かれており、実際attachClassesには war プラグインのプロパティを介して実行する必要がありました。

于 2010-11-06T02:51:39.537 に答える
1

アーティファクトバージョン-SNAPSHOTにサフィックスがないためでしょうか?

于 2010-11-05T02:25:19.467 に答える