无法在项目上执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile): 编译失败:

问题描述 投票:0回答:1

我在尝试清理或构建我的 Maven 项目时遇到错误。该错误与我的模型中的 getter/setter 相关,其顶部有 @Data 注释。尽管它们捆绑在 @Data 中,但我尝试将 @Getter 和 @Setter 包含在模型中以查看是否有任何更改,但无济于事。

完整错误:

    [INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  8.155 s
[INFO] Finished at: 2024-11-02T15:07:27Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile) on project: Compilation failure: Compilation failure: 
[ERROR] /Users/**/Documents/**/projects/**/src/main/java/com/example/**/controller/Controller.java:[88,14] cannot find symbol
[ERROR]   symbol:   method setImageUrl(java.lang.String)
[ERROR]   location: variable album of type com.example.**.model.**
[ERROR] /Users/**/Documents/**/projects/**/src/main/java/com/example/**/controller/Controller.java:[99,21] cannot find symbol
[ERROR]   symbol:   method setImageUrl(java.lang.String)
[ERROR]   location: variable newAlbum of type com.example.**.model.**

现在,我已经根据帖子建议对 pom.xml 进行了调整,但这似乎没有任何作用。他们唯一发生的变化是将 Java 从 21.0.4 更新为 21.0.5。恢复到 21.0.4 不会改变任何内容。另外,我尝试过使缓存失效并重新启动。

这是我的完整 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.3.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>**</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>**</name>
    <description>**</description>
    <url/>
    <licenses>
        <license/>
    </licenses>
    <developers>
        <developer/>
    </developers>
    <scm>
        <connection/>
        <developerConnection/>
        <tag/>
        <url/>
    </scm>
    <properties>
        <java.version>21</java.version>
    </properties>
    <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-cache</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.ben-manes.caffeine</groupId>
            <artifactId>caffeine</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.0.2</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jdk8</artifactId>
            <version>2.15.3</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.34</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.cloudinary</groupId>
            <artifactId>cloudinary-http45</artifactId>
            <version>1.39.0</version>
        </dependency>
        <dependency>
            <groupId>com.cloudinary</groupId>
            <artifactId>cloudinary-taglib</artifactId>
            <version>1.39.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.13.0</version>
                <configuration>
                    <source>21</source>
                    <target>21</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

编辑:

对于 mvn clean 构建成功,但对于 mvn package 不起作用:

 mvn clean
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------< com.example:** >---------------------
[INFO] Building ** 0.0.1-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- clean:3.3.2:clean (default-clean) @ ** ---
[INFO] Deleting /Users/**/Documents/**/projects/**/target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.851 s
[INFO] Finished at: 2024-11-02T15:30:01Z
[INFO] ------------------------------------------------------------------------
java spring-boot maven pom.xml lombok
1个回答
0
投票

根据错误日志,以下任一问题都可能是问题

  1. 请验证相册类中存在的变量 imageUrl

  2. 如果此字段已存在并且您正在使用 IntelliJ IDEA 请检查 lombok 插件是否已安装

© www.soinside.com 2019 - 2024. All rights reserved.