You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用frontend-maven-plugin构建Maven多模块项目报错求助

解决frontend-maven-plugin构建时缺失Jackson ObjectMapper的问题

我之前在使用frontend-maven-plugin构建前后端分离项目时也碰到过类似的类缺失问题,结合你尝试过的方法,给你几个针对性的解决方案:

1. 优先升级frontend-maven-plugin到新版本

旧版本的frontend-maven-plugin(比如1.7.5)存在一些依赖兼容问题,尤其是和Jackson相关的依赖冲突。建议你升级到更稳定的新版本,比如1.12.0(这个版本我亲测过兼容旧Node版本):

<plugin>
    <groupId>com.github.eirslett</groupId>
    <artifactId>frontend-maven-plugin</artifactId>
    <version>1.12.0</version>
    <configuration>
        <nodeVersion>v10.14.1</nodeVersion>
        <npmVersion>6.8.0</npmVersion>
        <workingDirectory>src/main/web/</workingDirectory>
    </configuration>
</plugin>

升级后重新执行mvn clean install,大概率能解决依赖缺失的问题。

2. 给插件显式添加Jackson依赖

如果因为项目限制不能升级插件版本,那你需要在插件自身的依赖配置中添加缺失的Jackson包(注意是在<plugin>下的<dependencies>块,不是项目根目录的<dependencies>):

<plugin>
    <groupId>com.github.eirslett</groupId>
    <artifactId>frontend-maven-plugin</artifactId>
    <version>1.7.5</version>
    <!-- 新增插件专属依赖 -->
    <dependencies>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.13</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-core-asl</artifactId>
            <version>1.9.13</version>
        </dependency>
    </dependencies>
    <configuration>
        <nodeVersion>v10.14.1</nodeVersion>
        <npmVersion>6.8.0</npmVersion>
        <workingDirectory>src/main/web/</workingDirectory>
    </configuration>
</plugin>

之前你可能是在项目全局依赖里添加的Jackson,但插件运行时用的是独立类加载器,必须给插件单独声明依赖才能生效。

3. 彻底清理Maven缓存并强制更新

有时候缓存的依赖文件损坏也会导致类缺失,执行以下步骤:

  • 删除本地仓库中~/.m2/repository/org/codehaus/jackson文件夹
  • 执行命令mvn clean install -U,-U参数会强制Maven更新所有依赖快照和远程仓库的最新版本

4. 检查Maven仓库配置

如果你的Maven settings.xml中配置了私有镜像,确认该镜像包含org.codehaus.jackson相关的包。如果没有,暂时切换到Maven中央仓库试试:

<mirrors>
    <mirror>
        <id>central</id>
        <mirrorOf>central</mirrorOf>
        <url>https://repo1.maven.org/maven2/</url>
    </mirror>
</mirrors>

内容的提问来源于stack exchange,提问作者Paris Karagiannopoulos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:07:58