Mavenアセンブリから「提供された」依存関係を除外する 質問する

Mavenアセンブリから「提供された」依存関係を除外する 質問する

Mavenアセンブリプラグインを使用して依存関係のあるjarをビルドしようとしています。を除外する範囲を提供したもの。

依存関係のある jar を assembly.xml ファイルにコピーし、POM での使用を構成しました。参考までに、次のとおりです。

<?xml version="1.0" encoding="UTF-8"?>
<assembly>
  <id>injectable-jar</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
      <unpack>true</unpack>
      <scope>runtime</scope>
    </dependencySet>
  </dependencySets>
  <fileSets>
    <fileSet>
      <directory>${project.build.outputDirectory}</directory>
    </fileSet>
  </fileSets>
</assembly>

providedスコープを に設定すると、まさに私が望んでいたものを含むjarファイルを作成できることが分かりました。しない欲しいのですが、その逆の動作をどうやって得るかがわかりません。

ベストアンサー1

これは少し面倒ですが、maven-dependency-plugin を使用してすべての依存関係をプロジェクトにコピー/解凍し、アセンブリ プラグインを使用してパッケージ化を行うことができます。

と目標copy-dependenciesunpack-dependenciesはオプションの除外範囲プロパティを設定すると、provided依存関係を省略できます。以下の設定では、すべての依存関係をtarget/libにコピーします。アセンブリプラグイン記述子を変更して、ファイルセットそれらの瓶を含めるためです。

更新: 動作することを確認するためにテストしました。アセンブリ プラグインをパッケージ フェーズにバインドするための構成と、アセンブリ記述子に関連する変更を追加しました。

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <executions>
    <execution>
      <id>copy-dependencies</id>
      <phase>process-resources</phase>
      <goals>
        <goal>copy-dependencies</goal>
      </goals>
      <configuration>
        <excludeScope>provided</excludeScope>
        <outputDirectory>${project.build.directory}/lib</outputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>
<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.2-beta-4</version>
  <executions>
    <execution>
      <id>jar-with-deps</id>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <descriptors>
      <descriptor>src/main/assembly/my-assembly.xml</descriptor>
    </descriptors>
  </configuration>
</plugin>

記述子の fileSet セクションはmy-assembly次のようになります。

<assembly>
  <fileSets>
    <fileSet>
      <directory>${project.build.directory}/lib</directory>
      <outputDirectory>/</outputDirectory>
      <includes>
        <include>*.*</include>
      </includes>
    </fileSet>
  </fileSets>
...

</assembly>

おすすめ記事