admin管理员组

文章数量:1400837

My @RequiredArgsConstructor is not working annotation is enabled lombok is installed

removed the imports all imports are ohk nothing wrong there

@Service
@RequiredArgsConstructor
public class PostServiceImpl implements PostService {
    private final PostRepository postRepository;
    private final ModelMapper modelMapper;
    @Override
    public List<PostDTO> getAllPosts() {
        return List.of();
    }

    @Override
    public PostDTO createNewPost(PostDTO inputPost) {
        return null;
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=".0.0" xmlns:xsi=";
    xsi:schemaLocation=".0.0 .0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.4.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.codingshuttle.anuj.prod-ready-features</groupId>
    <artifactId>prod-ready-features</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>prod-ready-features</name>
    <description>Demo project for Spring Boot and prod-ready-features</description>
    <url/>
    <licenses>
        <license/>
    </licenses>
    <developers>
        <developer/>
    </developers>
    <scm>
        <connection/>
        <developerConnection/>
        <tag/>
        <url/>
    </scm>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- .modelmapper/modelmapper -->
        <dependency>
            <groupId>.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>3.2.2</version>
        </dependency>


        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
            <plugin>
                <groupId>.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Did all these things

  • Added Lombok dependency in pom.xml.
  • Verified Lombok is present in mvn dependency:tree.
  • Installed the Lombok plugin in IntelliJ IDEA.
  • Restarted IntelliJ after installing the plugin.
  • Enabled annotation processing in IntelliJ settings.
  • Annotated the service class with @RequiredArgsConstructor.
  • Rebuilt the project using IntelliJ’s Rebuild Project.
  • Ran mvn clean compile from the terminal.
  • Checked IntelliJ Alt + 7 Structure tab to confirm constructor generation.
  • Validated Lombok dependency version is compatible with Java 17.
  • Used Invalidate Caches / Restart in IntelliJ.
  • Confirmed manually written constructor works, but Lombok-generated one doesn’t show effect.

本文标签: javaHow can I fix Lombok not working in IntelliJ IDEAStack Overflow