托管 Maven spring 引导依赖项未加载到 m2 文件夹

Managed maven spring boot dependencies not loaded to m2 folder

我正在尝试在我的 spring 引导项目中使用 lombok。我可以在 Effective POM 中看到 lombok 依赖,如下所示。

<dependency>
  <groupId>org.postgresql</groupId>
  <artifactId>postgresql</artifactId>
  <version>42.2.5</version>
</dependency>
<dependency>
  <groupId>org.projectlombok</groupId>
  <artifactId>lombok</artifactId>
  <version>1.18.6</version>
</dependency>
<dependency>
  <groupId>org.quartz-scheduler</groupId>
  <artifactId>quartz</artifactId>
  <version>2.3.1</version>

但是在m2文件夹中看不到jar文件,我不能在我的项目中使用它。 ex -> @Getter 无法识别。 但是,如果我将依赖项添加到我的实际 pom 中,如下所示。它被下载到 m2 文件夹,我可以在我的项目中使用它,但我收到一条警告,表明我正在覆盖托管依赖项。

<dependencies>
        <!-- <dependency> -->
        <!-- <groupId>org.springframework.boot</groupId> -->
        <!-- <artifactId>spring-boot-starter-actuator</artifactId> -->
        <!-- </dependency> -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!-- <dependency> -->
        <!-- <groupId>org.springframework.boot</groupId> -->
        <!-- <artifactId>spring-boot-starter-security</artifactId> -->
        <!-- </dependency> -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

        <!-- Does not work if i dont add below dependency -->

        <dependency>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <version>1.18.6</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

谁能解释一下这种行为?我希望在不将它添加到 pom.xml 的情况下加载它,因为它在有效的 pom.xml 中。

您需要设置这个选项:

或 select "Enable Auto-Import" 在这个 pop-up 菜单(出现在右下角)当你改变你的 pom 时。

如果您在父 POM 中使用 <dependencyManagement>,那不会强制您的项目实际依赖于这些库,因此 Maven 不会下载它。

它需要出现在正常的 <dependencies> 部分下,以实际表明您的项目需要依赖项,从而强制 Maven 下载它。