1

I am trying to use lombok in my spring boot project. I can see lombok dependency in the Effective POM like below.

<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>

Buti can not see the jar file in m2 folder, and i can not use it in my project. ex -> @Getter is not recognized. However if i add the dependency to my actual pom like below. It is downloaded to m2 folder and i can use it in my project, but i get a warning indicating that i am overriding the managed dependency.

<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>

Could anyone explain this behaviour please? I am expecting it to be loaded without me adding it to pom.xml since it is in the effective pom.

Rakesh
  • 4,004
  • 2
  • 19
  • 31
  • 1
    Is the first dependency specification inside a `` block? If so, that won't force maven to load it. – Mike Jul 01 '19 at 15:11
  • 1
    @Mike You are right it was in `` thanks for ponting me in that direction. The situation is explained in this link [https://stackoverflow.com/questions/2619598/differences-between-dependencymanagement-and-dependencies-in-maven] if anyone is interested. – teslacoil833 Jul 01 '19 at 15:40
  • Ah, just saw this comment. Glad you got it sorted out! – Mike Jul 01 '19 at 15:43

2 Answers2

0

You need to set this option: enter image description here

Or select "Enable Auto-Import" at this pop-up menu (which appear at bottom right corner) when you changing your pom.

enter image description here

HereAndBeyond
  • 794
  • 1
  • 8
  • 17
0

If you're using <dependencyManagement> in your parent POM, that won't force your project to actually depend on those libraries, and thus Maven will not download it.

It needs to appear under the normal <dependencies> section to actually indicate your project needs the dependency, and thus force Maven to download it.

Mike
  • 4,722
  • 1
  • 27
  • 40