0

I am trying to create a project with microservices, but i get the error "variable X not initialized in the default constructor" when trying to use the annotation @RequiredArgsConstructor from Lombok. The only solutions found on the internet are to check Obtain processors from project classpath (see image below) but that did not solve it for me.

enter image description here

The root pom is:

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.ku.survey</groupId>
    <artifactId>survey</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <properties>
        <java.version>21</java.version>
        <spring-boot.version>3.2.5</spring-boot.version>
        <mapstruct.version>1.5.5.Final</mapstruct.version>
<!--        <flyway.version>10.15.0</flyway.version>-->
        <postgresql.version>42.7.2</postgresql.version>
        <maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
        <maven.compiler.proc>full</maven.compiler.proc>
    </properties>

    <dependencyManagement>
        <dependencies>
            <!-- Spring Boot BOM -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!-- MapStruct -->
            <dependency>
                <groupId>org.mapstruct</groupId>
                <artifactId>mapstruct</artifactId>
                <version>${mapstruct.version}</version>
            </dependency>
            <dependency>
                <groupId>org.mapstruct</groupId>
                <artifactId>mapstruct-processor</artifactId>
                <version>${mapstruct.version}</version>
            </dependency>

<!--            &lt;!&ndash; Flyway &ndash;&gt;-->
<!--            <dependency>-->
<!--                <groupId>org.flywaydb</groupId>-->
<!--                <artifactId>flyway-database-postgresql</artifactId>-->
<!--                <version>${flyway.version}</version>-->
<!--            </dependency>-->

            <!-- PostgreSQL -->
            <dependency>
                <groupId>org.postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <version>${postgresql.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${maven-compiler-plugin.version}</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                        <annotationProcessorPaths>
                            <path>
                                <groupId>org.mapstruct</groupId>
                                <artifactId>mapstruct-processor</artifactId>
                                <version>${mapstruct.version}</version>
                            </path>
                        </annotationProcessorPaths>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <modules>
        <module>user</module>
        <module>survey-template</module>
        <module>experiment</module>
    </modules>
</project>

And the pom for the user microservice is:

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.ku.survey</groupId>
        <artifactId>survey</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>user</artifactId>
    <name>Survey User Microservice</name>

    <properties>
        <maven.compiler.release>21</maven.compiler.release>
    </properties>

    <dependencies>
        <!-- Spring Boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</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-jdbc</artifactId>
        </dependency>

        <!-- DB -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!-- Flyway engine -->
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
<!--            <version>10.15.0</version>-->
        </dependency>

<!--        <dependency>-->
<!--            <groupId>org.flywaydb</groupId>-->
<!--            <artifactId>flyway-database-postgresql</artifactId>-->
<!--            <version>10.15.0</version>-->
<!--        </dependency>-->

        <!-- MapStruct -->
        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct-processor</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*</include> <!-- Allow all resources, not just .sql -->
                </includes>
            </resource>
        </resources>
    </build>
</project>

Does anyone have any tips? I have been stuck on this for a while now.

This is an example of code that gets caught in the error:

@RequiredArgsConstructor
@Service
public class UserWebServiceImpl implements UserWebService {

    private final UserMapper userMapper;
    private final UserPortInServiceImpl createUserPortInService;

    @Override
    public void createAccount(CreateUserRequestDto createUserRequestDto) {
//validation service for the input
        createUserPortInService.createUser(
                userMapper.toCreateUserRequest(createUserRequestDto));
    }
}
3
  • 1
    Which java version are you compiling with? Note that the pom file you wrote doesn't match instructions - JDK24 disabled automatic discovery of annotation processors, hence the need to tell maven to enable them. Commented May 27 at 20:30
  • projectlombok.org/setup/maven why using old MapStruct version? Commented May 27 at 21:49
  • oh, thank you. it seems i managed to get it working with JDK21 and obtain processors from classpath. I have also added the path to the annotation processors: <path> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.32</version> <!-- latest version recommended --> </path> Commented May 28 at 22:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.