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

Maven clean未清理全部目录:仅删除node_modules,node目录留存原因

Maven Clean命令仅删除node_modules不删除node目录的原因及修复方案

核心原因

  1. 重复插件声明导致配置覆盖:你在pom.xml中重复定义了maven-clean-plugin,Maven构建时同一个插件的多次配置会被最后一次声明完全覆盖,因此只有针对node_modules的配置生效,node目录的清理配置被直接忽略。
  2. XML结构错误:<followSymlinks>标签被错误嵌套在<includes>标签内部,这会导致该配置无法被插件正确识别(不过这不是本次问题的直接诱因)。

修复后的正确配置

将两个清理规则合并到同一个maven-clean-plugin配置中,同时修正XML结构:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-clean-plugin</artifactId>
    <version>2.4.1</version>
    <configuration>
        <filesets>
            <fileset>
                <directory>src/main/webapp/form-src/node</directory>
                <includes>
                    <include>**</include>
                </includes>
                <followSymlinks>false</followSymlinks>
            </fileset>
            <fileset>
                <directory>src/main/webapp/form-src/node_modules</directory>
                <includes>
                    <include>**</include>
                </includes>
                <followSymlinks>false</followSymlinks>
            </fileset>
        </filesets>
    </configuration>
</plugin>

额外优化建议

如果需要直接删除整个node和node_modules目录(而非仅删除目录内的内容),可以给每个<fileset>添加<deleteDirectory>true</deleteDirectory>配置:

<fileset>
    <directory>src/main/webapp/form-src/node</directory>
    <includes>
        <include>**</include>
    </includes>
    <followSymlinks>false</followSymlinks>
    <deleteDirectory>true</deleteDirectory>
</fileset>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 03:05:10