overview

Origin

At the beginning, Hutool provided two ways to import:

  1. Import hutool-all to use all tool class functions

  2. Import hutool-xxx separately for individual module use

Later, Mr. Tan, the author of t-io, proposed the idea of introducing a bom package to import all the sub-modules at once and then exclude the unused ones. At first, I was reluctant to this idea, thinking it was not useful (but actually I couldn’t figure out how to do it…)

Later on, I became familiar with this part of Maven and thus the hutool-bom module came into existence!

However, there has been controversy about this module because a real bom package is a module management package. The correct way to open it is to import it and then import the required modules (just without duplicate version numbers). The exclusion method in Hutool becomes very strange, really headache.

The turning point came from an issue: BOM should be declared in dependencyManagement for import

@JasonMing gave a great solution, which can give both ways a chance, so I finally let go and the bom module now is very flexible!

Introduction

The entire bom module consists of only one pom.xml file with both dependencyManagement and dependencies declared. So we can import different needs according to different requirements.

Usage

Import method

If you want to import Hutool like Spring Boot and let the sub-modules determine which modules to use, you can add the following to the parent module:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-bom</artifactId>
            <version>${hutool.version}</version>
            <type>pom</type>
            <!-- Note that it's 'import' here -->
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

In the sub-module, you can import the modules you need:

<dependencies>
    <dependency>
        <groupId>cn.hutool</groupId>
        <artifactId>hutool-http</artifactId>
    </dependency>
</dependencies>

When using the import method, only the dependencyManagement configuration in hutool-bom will be introduced, and other configurations will not take effect under this reference method.

Exclude method

If you import many modules but a few of them are not used, you can:

<dependencies>
    <dependency>
        <groupId>cn.hutool</groupId>
        <artifactId>hutool-bom</artifactId>
        <version>${hutool.version}</version>
        <!-- Whether to add this sentence or not, it can run, and the difference is whether there is a warning -->
        <type>pom</type>
        <exclusions>
            <exclusion>
                <groupId>cn.hutool</groupId>
                <artifactId>hutool-system</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

This configuration will pass all the content of dependencies in hutool-bom. Currently, all dependencies in hutool-bom have set versions, which means that even if there is dependencyManagement in hutool-bom, it will not have any effect when Maven resolves.