1

質問: Nexus で再デプロイが無効になっている場合、2 つの排他的プロファイルを持つ Maven プロジェクトをどのようにリリースすればよいですか?

例 (編集済み)pom.xml : 2 つの異なる耳を生成する (P1 と P2) に2 つのプロファイルを持つ Maven プロジェクト MyArtifact があります。各プロファイルmaven-ear-pluginは、異なるモジュールを含めて を自動生成するように構成しますapplication.xml。生成されるアーティファクトはMyArtifact-1.0-P1.ear(2 つの戦争モジュール) とMyArtifact-1.0-P2.ear(3 つの戦争モジュール) です。

問題 1 (nexus への再デプロイ) :

  1. " " を実行するとmvn deploy -P P1、すべてうまくいきます (war と pom が Nexus にデプロイされます)。
  2. mvn deploy -P P2" " エラーを実行すると! Nexus は、pom.xml の再デプロイについて不平を言います。

問題 2 (maven-release-plugin) :

を使用しmaven-release-pluginて複数のプロファイルをリリースする場合、maven は多くのことを行います (チェックアウトして CSM にタグを付ける、pom バージョンを更新する、タグに切り替える、CSM にコミットするなど...)。少なくとも、プロファイルの実行ごとに再リリース/再タグ付けする必要があるのは効率的でも実用的でもありません。

4

2 に答える 2

8

簡単な答え。不可能です。この問題は、この関係において悪であるプロファイルの使用に基づいています。

このような問題の解決策は、このビルドの結果である 2 つの war ファイルを生成できる Maven ビルドを作成することです。

次のような環境ごとに異なるプロパティがあると思います。

.
|-- pom.xml
`-- src
    |-- main
    |   |-- java
    |   |-- resources
    |   |-- environment
    |   |   |-- test
    |   |   |   `-- database.properties
    |   |   |-- qa
    |   |   |   `-- database.properties
    |   |   `-- production
    |   |       `-- database.properties
    |   `-- webapp

つまり、プロパティ ファイルの内容のみが異なる 2 つの war ファイルを作成する必要があります。上記では3つの環境があります。

必要なのは、次のような各環境のアセンブリ記述子です。

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">

  <id>test</id>
  <formats>
    <format>war</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
      <unpack>true</unpack>
      <useProjectArtifact>true</useProjectArtifact>
    </dependencySet>
  </dependencySets>
  <fileSets>
    <fileSet>
      <outputDirectory>WEB-INF</outputDirectory>
      <directory>${basedir}/src/main/environment/test/</directory>
      <includes>
        <include>**</include>
      </includes>
    </fileSet>
  </fileSets>
</assembly>

この場合、次のような maven-assembly-plugin の適切な実行:

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
      <execution>
        <id>test</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
        <configuration>
          <descriptors>
            <descriptor>${project.basedir}/src/main/assembly/test.xml</descriptor>
          </descriptors>
        </configuration>
      </execution>
      <execution>
        <id>qa</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
        <configuration>
          <descriptors>
            <descriptor>${project.basedir}/src/main/assembly/qa.xml</descriptor>
          </descriptors>
        </configuration>
      </execution>
      <execution>
        <id>production</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
        <configuration>
          <descriptors>
            <descriptor>${project.basedir}/src/main/assembly/production.xml</descriptor>
          </descriptors>
        </configuration>
      </execution>
    </executions>
  </plugin>

これにより、次の方法で maven が 1 回実行されます。

mvn package

これにより、異なるプロパティ ファイルまたは異なる内容のファイルを含む 3 つの異なる war ファイルが生成されます。これは、完全に機能するプロファイルのないソリューションであり、次のような名前の 3 つの異なる war ファイルを展開します。

  1. artifactId-バージョン-test.war
  2. artifactId-バージョン-qa.war
  3. artifactId-version-production.war

それが問題を解決するために必要な結果です。

于 2013-04-16T15:58:28.000 に答える
1

うん!

プロファイルを使用する代わりに、Maven<executions>機能を使用しています。プロファイルごとに 1 回実行します。実行ごとに、異なる作業フォルダにリソースを生成する必要があります。各アーティファクトには異なる分類子があります。Maven をデプロイすると、3 つのアーティファクト (pom、ear、ear) が検出され、Nexus に正常にデプロイされます。

以下に例を示します。問題があることをお知らせください。

<plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ear-plugin</artifactId>
        <executions>
            <execution>
                <!-- Disable default execution -->
                <id>default-ear</id>
                <phase>none</phase>
            </execution>
            <execution>
                <!-- Disable default execution -->
                <id>default-generate-application-xml</id>
                <phase>none</phase>
            </execution>
            <execution>
                <!-- execution for profile P1 -->
                <id>P1</id>
                <goals>
                    <goal>ear</goal>
                    <goal>generate-application-xml</goal>
                </goals>
                <configuration>
                    <!-- Different working directory for each profile (very important) -->
                    <workDirectory>target/P1</workDirectory>
                    <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
                    <generateApplicationXml>true</generateApplicationXml>
                    <displayName>MyArtifactLibraryP1</displayName>
                    <!-- Different classifier for each profile (very important) -->
                    <classifier>P1</classifier>
                    <modules>
                        <jarModule>
                            <groupId>com.example</groupId>
                            <artifactId>MyWar1</artifactId>
                            <includeInApplicationXml>true</includeInApplicationXml>
                        </jarModule>
                        <jarModule>
                            <groupId>com.example</groupId>
                            <artifactId>MyWar2</artifactId>
                            <includeInApplicationXml>true</includeInApplicationXml>
                        </jarModule>
                    </modules>
                </configuration>
            </execution>
            <execution>
                <id>P2</id>
                <goals>
                    <goal>ear</goal>
                    <goal>generate-application-xml</goal>
                </goals>
                <configuration>
                    <workDirectory>target/P2</workDirectory>
                    <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
                    <generateApplicationXml>true</generateApplicationXml>
                    <displayName>MyArtifactLibraryP2</displayName>
                    <classifier>P2</classifier>
                    <modules>
                        <jarModule>
                            <groupId>com.example</groupId>
                            <artifactId>MyWar1</artifactId>
                            <includeInApplicationXml>true</includeInApplicationXml>
                        </jarModule>
                        <jarModule>
                            <groupId>com.example</groupId>
                            <artifactId>MyWar2</artifactId>
                            <includeInApplicationXml>true</includeInApplicationXml>
                        </jarModule>
                        <jarModule>
                            <groupId>com.example</groupId>
                            <artifactId>MyWar3</artifactId>
                            <includeInApplicationXml>true</includeInApplicationXml>
                        </jarModule>
                    </modules>
                </configuration>
            </execution>
        </executions>
    </plugin>
于 2013-06-12T08:04:26.963 に答える