Docker构建时Maven打包报错:构造器不匹配、找不到符号(疑与Lombok相关)
问题
项目结构:
root src pom.xml Dockerfile docker-compose.yaml
Dockerfile 内容
FROM openjdk:22-ea-19-jdk-bookworm # Install tools RUN apt update && apt install -y maven vim # Set working directory WORKDIR /app # Copy all project files at once COPY . . # Build the project (download dependencies and compile) RUN mvn clean package -DskipTests # Expose port EXPOSE 8082 # Run the jar CMD ["java", "-jar", "target/myapp.jar"]
执行以下命令构建镜像:
docker build -t myappimage .
构建过程中执行mvn clean package步骤失败,出现编译错误:
45.79 [INFO] Recompiling the module because of changed dependency. 45.83 [INFO] Compiling 55 source files with javac [debug parameters release 21] to target/classes 52.75 [INFO] ------------------------------------------------------------- 52.76 [ERROR] COMPILATION ERROR : 52.76 [INFO] ------------------------------------------------------------- 52.76 [ERROR] /app/src/main/java/com/myapp/DataInitializer.java: [37,38] constructor DogBreed in class com.myapp.dog.entity.DogBreed cannot be applied to given types; 52.76 required: no arguments 52.76 found: <nulltype>,com.myapp.dog.DogBreedEnum 52.76 reason: actual and formal argument lists differ in length 52.76 [ERROR] /app/src/main/java/com/myapp/DataInitializer.java: [38,33] incompatible types: inference variable T has incompatible bounds 52.76 equality constraints: com.myapp.dog.entity.DogBreed 52.76 lower bounds: java.lang.Object 52.76 [ERROR] /app/src/main/java/com/myapp/DataInitializer.java: [49,25] constructor Person in class com.myapp.Person cannot be applied to given types; 52.76 required: no arguments 52.76 found: <nulltype>,java.lang.String,int,int 52.76 reason: actual and formal argument lists differ in length
实体类使用Lombok注解生成构造器,相关注解如下:
@Entity @Getter @Setter @NoArgsConstructor @AllArgsConstructor
此外还有如下报错:
52.85 [ERROR] /app/src/main/java/com/myapp/dog/service/DogService.java:[122,36] cannot find symbol 52.85 [ERROR] symbol: method getIsGood() 52.85 [ERROR] location: variable dog of type com.myapp.dog.entity.Dog
但本地直接执行mvn package可以正常生成jar包,且通过java -jar myapp.jar能正常运行。请问这是Lombok导致的问题吗?
内容的提问来源于stack exchange,提问作者parsecer
相关产品推荐
相关产品推荐

