运行Docker Compose时Maven编译报错“invalid target release: 17”的解决求助
运行Docker Compose时Maven编译报错“invalid target release: 17”的解决求助
大家好,我最近在运行docker-compose.yml的Compose Deployment时遇到了一个Maven编译错误,折腾了好久没找到解决办法,来求助一下!
具体报错信息如下:
#0 62.23 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project stack-overflow: Fatal error compiling: invalid target release: 17 -> [Help 1] #0 62.23 [ERROR] #0 62.23 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. #0 62.23 [ERROR] Re-run Maven using the -X switch to enable full debug logging. #0 62.23 [ERROR] #0 62.23 [ERROR] For more information about the errors and possible solutions, please read the following articles: #0 62.23 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
我本地确实一直用的是Java 17,之前也没出过问题,本地环境信息如下:
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T22:49:05+03:00) Maven home: C:\Users\Семья\.m2\wrapper\dists\apache-maven-3.5.3-bin\2c22a6s60afpuloj4v181qvild\apache-maven-3.5.3 Java version: 17.0.5, vendor: Amazon.com Inc. Java home: C:\Users\NadChel\.jdks\corretto-17.0.5 Default locale: ru_RU, platform encoding: UTF-8 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
我的pom.xml里已经明确指定了Java版本为17,相关配置片段如下:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.8</version> <relativePath/> </parent> <properties> <java.version>17</java.version> <!-- other props --> </properties> <!-- ... --> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>${java.version}</source> <target>${java.version}</target>
后来我还更新了maven-compiler-plugin的版本到3.11.0,并且添加了MapStruct和Lombok相关的注解处理器配置——因为项目里用到了MapStruct,官方文档明确说需要这么配置,同时也为了支持Lombok:
<version>3.11.0</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> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> </path> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok-mapstruct-binding</artifactId> <version>0.2.0</version> </path> </annotationProcessorPaths> <compilerArgs> <arg> -Amapstruct.unmappedTargetPolicy=IGNORE </arg> </compilerArgs> </configuration>
另外附上我的docker-compose.yml配置,不确定有没有关联:
version: '3.8' services: stack_overflow_postgres: image: postgres:15 container_name: stack_overflow_postgres restart: always environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres123 - POSTGRES_DB=stack_overflow_postgres ports: - '5411:5432' stack_overflow_elasticsearch: image: docker.elastic.co/elasticsearch/elasticsearch:7.15.0 container_name: stack_overflow_elasticsearch restart: always environment: - discovery.type=single-node - ELASTIC_PASSWORD=your_password - xpack.security.enabled=true ports: - '9200:9200' - '9300:9300' stack_overflow_app: build: . depends_on: - stack_overflow_postgres - stack_overflow_elasticsearch environment: - SPRING_DATASOURCE_URL=jdbc:postgresql://stack_overflow_postgres:5432/stack_overflow_postgres - SPRING_DATASOURCE_USERNAME=postgres - SPRING_DATASOURCE_PASSWORD=postgres123 - SPRING_ELASTICSEARCH_REST_URIS=http://stack_overflow_elasticsearch:9200 - SPRING_ELASTICSEARCH_REST_USERNAME=elastic - SPRING_ELASTICSEARCH_REST_PASSWORD=your_password ports: - '8080:8080'
我已经谷歌过相关问题,但没找到有效的解决办法。看到过有回答提到可能是Spring/Tomcat版本冲突,但我用的都是Spring Boot Starter,应该会自动处理依赖兼容问题才对。而且之前用Docker跑测试也没问题,这次不知道哪里出了问题,有没有大佬能指点一下该怎么排查解决?
备注:内容来源于stack exchange,提问作者Sergey Zolotarev
相关产品推荐
相关产品推荐

