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

从现有项目创建Maven Archetype时.gitignore文件缺失求助

解决Maven Archetype创建时.gitignore文件缺失的问题

方案一:执行创建命令时显式指定包含.gitignore

直接在archetype:create-from-project命令中添加包含参数,强制插件纳入.gitignore文件:

mvn archetype:create-from-project -Darchetype.includes=**/.gitignore

方案二:修改生成的Archetype项目配置

执行完create-from-project后,进入target/generated-sources/archetype目录,做两处修改:

  1. 调整maven-resource-plugin配置
    打开该目录下的pom.xml,更新资源插件配置,明确包含.gitignore:
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <configuration>
        <defaultExcludes>false</defaultExcludes>
        <includes>
            <include>**/.gitignore</include>
            <include>**/*</include>
        </includes>
    </configuration>
</plugin>
  1. 更新archetype-metadata.xml
    找到src/main/resources/META-INF/maven/archetype-metadata.xml,在<fileSets>中添加.gitignore的文件集配置:
<fileSets>
    <fileSet filtered="true" packaged="false">
        <directory>src/main/resources</directory>
        <includes>
            <include>**/.gitignore</include>
        </includes>
    </fileSet>
    <!-- 保留原有的其他fileSet配置 -->
</fileSets>

修改完成后,在该目录下执行mvn install重新安装archetype,之后使用该archetype创建项目时就能包含.gitignore文件。

方案三:检查原项目的资源排除规则

确认原项目的pom.xml中,maven-resource-plugin没有显式排除.gitignore文件,避免原项目的配置影响archetype的资源收集。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 09:50:57