What does the import scope do, and how is it different from every other scope?
answer
- import = version management, NOT a classpath
- only on <type>pom</type> in <dependencyManagement>
- merges a BOM's dependencyManagement
- works around single <parent> inheritance
- first declared BOM wins on conflicts
basics
~20 simport is not a classpath scope. Used only on a pom-typed dependency inside <dependencyManagement>, it merges another POM's <dependencyManagement> (a BOM) into yours, so you inherit managed versions without adding any jar to a classpath.
solid answer
~40 simport is fundamentally different from the five classpath scopes: it never puts anything on the compile, test, or runtime classpath. It is only valid on a dependency with <type>pom</type> declared inside <dependencyManagement>, and its effect is to pull the referenced POM's own <dependencyManagement> section into yours. That referenced POM is typically a BOM (Bill Of Materials) such as spring-boot-dependencies or jackson-bom, which centralizes a curated, consistent set of versions. After importing, you declare your actual dependencies in <dependencies> without versions, and they resolve to the BOM-managed versions. It exists because Maven only supports single inheritance via <parent>; import lets you compose version constraints from multiple BOMs. It is the standard way to align versions across a multi-module project and avoid conflicts.
code
xml · 11 lines<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.3.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>go deeper
Know import is used to pull in a BOM's versions, not jars.
Write a correct import block with type pom in dependencyManagement and omit versions on dependencies.
Compose multiple BOMs, reason about ordering/conflict resolution, and verify with effective-pom.
Define an org BOM strategy (corporate parent + imported third-party BOMs) to enforce consistent versions across many repos.
## import is not about classpaths The other five scopes (compile, provided, runtime, test, system) decide **which classpath** a jar lands on. `import` does none of that — it is a **version-management directive**. It only works in one place: a `<dependency>` of `<type>pom</type>` with `<scope>import</scope>`, placed inside **`<dependencyManagement>`** (not `<dependencies>`). ## What it actually does It takes the target POM's **`<dependencyManagement>`** block and inlines it into yours. The target is almost always a **BOM (Bill Of Materials)**: a special POM that contains only managed versions (and sometimes exclusions) for a family of artifacts. ```xml <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>3.3.0</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <!-- no version: it comes from the imported BOM --> </dependency> </dependencies> ``` ## Why it exists - Maven supports only **single `<parent>` inheritance**. If you want managed versions from *several* BOMs (Spring, Jackson, a testing BOM), you cannot inherit them all via `<parent>`. `import` lets you compose **many** BOMs. - It **centralizes versions**: declare once in the BOM, omit versions everywhere else, so every module uses the same, conflict-free set. ## Important nuances - import only affects **`<dependencyManagement>`** (version constraints), never the dependency graph directly. You still add the actual dependencies in `<dependencies>`. - Ordering matters: if two imported BOMs manage the same artifact, the **first one declared wins** (it is processed in declaration order, and an already-defined managed version is not overridden). - A BOM imported with `import` does **not** transitively bring in *its* parent's dependencyManagement in the same way as inheritance — only the dependencyManagement of the imported POM (after its own interpolation) is merged. ## How to verify Run `mvn help:effective-pom` to see the fully resolved `<dependencyManagement>` after imports, or `mvn dependency:tree` to confirm the versions that were actually selected.
- Why use import instead of a <parent> for a BOM?Maven allows only one parent. import lets you compose managed versions from multiple BOMs, and keeps your parent free for your own corporate parent POM.
- Does importing a BOM add any jars to your build?No. It only contributes managed versions to <dependencyManagement>. You still declare the actual dependencies in <dependencies> (without versions).
- If two imported BOMs manage the same artifact differently, which wins?The one declared first; Maven processes dependencyManagement in order and does not override an already-set managed version.
saying these in an interview costs you the question
- Treating import as a normal classpath scope that adds jars.
- Putting an import dependency in <dependencies> instead of <dependencyManagement>.
- Forgetting <type>pom</type>, which is required for import.