You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为特定平台(如Wildfly)构建WAR时,过滤已提供依赖的优选方案

Which Approach is Better for WildFly WAR Builds?

Great question! When building WARs for containers like WildFly, choosing between using a platform BOM to mark dependencies as provided vs. using the Maven War Plugin to exclude dependencies can make a big difference in maintainability and reliability. Let's break down both options:

Using a Platform BOM with provided Scope

This is the recommended approach for most cases, and here's why:

  • Version Consistency: Platform BOMs (like WildFly's official BOM) are maintained to align exactly with the dependencies included in the container. When you import the BOM and mark dependencies as provided, you're guaranteed that the version your code compiles against matches what WildFly provides at runtime—no more jar version conflicts or runtime surprises.
  • Clear Intent: Anyone looking at your pom.xml can immediately see which dependencies are supplied by the application server, making the project structure easier to understand. You don’t have to dig through plugin configurations to figure out what’s excluded.
  • Low Maintenance: When you upgrade WildFly, you just update the BOM version in your pom.xml—all relevant provided dependencies will automatically use the correct version for the new server release. No need to manually adjust exclusion lists.

The only minor downside is if you have a niche dependency that isn’t covered by the official BOM, but those cases are rare, and you can always handle those exceptions individually.

Using the Maven War Plugin to Exclude Dependencies

This approach has its use cases, but it’s generally less ideal:

  • Prone to Errors: You have to manually list every dependency you want to exclude, which is easy to mess up—you might miss a transitive dependency or exclude something that shouldn’t be excluded.
  • Version Mismatch Risks: Even if you exclude a dependency, if your code was compiled against a different version than what WildFly provides, you could hit runtime errors (like NoSuchMethodError) that are hard to debug.
  • High Maintenance: Every time WildFly updates or your project adds new dependencies, you have to review and update the exclusion list. This becomes a tedious chore over time.

Final Verdict

Stick with the platform BOM + provided scope approach. It’s cleaner, more reliable, and far easier to maintain long-term. If you have a one-off case where you need to exclude a dependency that isn’t covered by the BOM, you can combine it with a small War Plugin exclusion, but the BOM should be your primary strategy.

内容的提问来源于stack exchange,提问作者JF Meier

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 09:00:13