以下の内容はhttps://blog1.mammb.com/entry/2025/12/22/000000より取得しました。


Gradle 9 で変更された ear / war プラグインのアーティファクト生成

blog1.mammb.com


はじめに

Gradle 9 では ear/war プラグインで生成されるアーティファクトや archives configuration が変更になりました。

リリースノートでの記載はありませんが、マイグレーションガイド では以下のように説明されています。

Ear and War plugins build all artifacts with assemble

Prior to Gradle 9.0.0, applying multiple packaging plugins (e.g., ear, war, java) to the same project resulted in special behavior where only one artifact type was built during assemble. For example:

Applying the ear plugin would skip building war and jar artifacts.

Applying the war plugin would skip building the jar.

This special handling has been removed in Gradle 9.0.0. Now, if multiple packaging plugins are applied, all corresponding artifacts will be built when running the assemble task. For example, a project applying the ear, war, and java plugins will now produce .ear, .war, and .jar files during assemble.

旧来は、war プラグインを適用すると、jar の生成が無効化されていたが、Gradle 9 からは、war プラグインは war と jar の双方を出力するようになったとの事(ear プラグインの場合は jar と war が対象)。

Gradle 9.2.1 の The War Plugin のドキュメントには以下のように、jar の生成が無効化される旨が記載されたままですが・・・

The War plugin extends the Java plugin to add support for assembling web application WAR files. It disables the default JAR archive generation of the Java plugin and adds a default WAR archive task.


archives configuration についても同様で、以下のように説明されています。

Ear and War plugins contribute all artifacts to the archives configuration

In previous versions of Gradle, applying multiple packaging plugins (ear, war, java) resulted in selective behavior for the archives configuration. For example:

Applying the ear plugin excluded jar and war artifacts from archives.

Applying the war plugin excluded the jar artifact from archives.

This behavior has been removed in Gradle 9.0.0. Now, when multiple packaging plugins are applied, all related artifacts—EAR, WAR, and JAR—are included in the archives configuration.

Gradle no longer implicitly builds certain artifa

Gradle 9 からは、war プラグインは war と jar の双方が archives configuration に含まれるようになったとの事。

プラグイン側で暗黙裡に選別するのではなく、不要なものは開発者が明示的に選別するという方向性になった模様です。


ということで、war プラグインでビルドすると build\libs\app.jar build\libs\app.war の2つが成果物として生成されることになります(旧来は build\libs\app.war のみ)。


jar タスクの生成を抑止する

以下のように jar タスクを明示的に無効化することで、従来と同じ挙動にすることができます。

plugins {
    war
}
// ...
tasks.jar {
    enabled = false
}

build\libs\app.jar のような jar が生成されなくなります。


archives configuration から jar を除外する

何らかの理由で jar は生成したいが、成果物リストからは除外したい場合は以下のようにフィルタリングできます。

configurations.archives.get().artifacts.removeIf { it.extension != "war" }






以上の内容はhttps://blog1.mammb.com/entry/2025/12/22/000000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14