maven项目生成手脚架

每个公司都有一套自己的工程模板,为了提高创建新工程的效率,以及统一工程规范,这里使用maven自带的功能archetype来产出一份工程脚手架。

  • idea中安装插件Maven Archetype Catalogs,直接在Plugins里搜索安装

  • 手动新建maven多module工程 或者打开在想让当前项目变成手脚架的项目工程

  • 在工程根目录下执行命令:mvn archetype:create-from-project,会生成 target 目录

  • 进到 target/generated-sources/archetype/src/main/resources/archetype-resources/pom.xml 里,增加 模块

    <modules>
        <module>${rootArtifactId}-client</module>
        <module>${rootArtifactId}-adapter</module>
        <module>${rootArtifactId}-app</module>
        <module>${rootArtifactId}-domain</module>
        <module>${rootArtifactId}-infrastructure</module>
        <module>start</module>
    </modules>
  • 进到 target/generated-sources/archetype 目录,执行命令: mvn install

  • 这一步执行完成之后,会在你本地的maven仓库中生成两个文件,一个是:工程名-archetype 文件,另一个是指向前面 archetype 文件的坐标xml 该文件位于 maven 仓库的根目录:archetype-catalog.xml

<?xml version="1.0" encoding="UTF-8"?>
<archetype-catalog xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0 http://maven.apache.org/xsd/archetype-catalog-1.0.0.xsd"
    xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <archetypes>
    <archetype>
      <groupId>com.xxx</groupId>
      <artifactId>fsm-archetype</artifactId>
      <version>1.0.0-SNAPSHOT</version>
      <description>fsm-archetype</description>
    </archetype>
  </archetypes>
</archetype-catalog>


然后当前idea 手脚架目录内就有了该手脚架了

posted @ 2022-10-08 17:24  liuhuayiye  阅读(256)  评论(0编辑  收藏  举报