一、创建 archetype 项目
这里就跟创建一个普通项目是一样的,不同的地方,在于 pom.xml的配置
在 build 节点下增加
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<propertyFile>archetype.properties</propertyFile>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
archetype.properties 用于忽略哪些文件不要打包进新项目中
https://maven.apache.org/archetype/maven-archetype-plugin/create-from-project-mojo.html
archetype.properties内容
# 打包过滤文件
excludePatterns=.idea/*,/**/.idea/*,/**/node_modules/**/*,readme.md,archetype.properties,*.bat,*.iml,/**/*.iml,*.ps1
二、生成骨架文件
在工程根目录下执行:脚手架编译
mvn archetype:create-from-project
三、修改包名
为了创建新项目后,子模块的名称也一起改变。需要做如下修改。
修改文件名
target/generated-sources/archetype/src/main/resources/archetype-resources
target\generated-sources\archetype\target\classes\archetype-resources
目录下的 所有maven开头的目录改为
rootArtifactId
比如,把maven-app改为 rootArtifactId-app (如果你的子模块不是maven开头的,请用其它的修改)
修改内容
\target\generated-sources\archetype\target\classes\META-INF\maven\archetype-metadata.xml \target\generated-sources\archetype\src\main\resources\META-INF\maven\archetype-metadata.xml 里的内容
<module id="maven-app" dir="maven-app" name="maven-app">
改为
<module id="${rootArtifactId}-app" dir="__rootArtifactId__-app" name="${rootArtifactId}-app">
修改各引用包之间的名称
把各子项目之间的 pom.xml里 maven改为${rootArtifactId}
比如:把 maven-service改为 ${rootArtifactId}-service
<dependency>
<groupId>com.gisquest</groupId>
<artifactId>maven-service</artifactId>
<version>${project.version}</version>
</dependency>
改为
<dependency>
<groupId>com.gisquest</groupId>
<artifactId>${rootArtifactId}-service</artifactId>
<version>${project.version}</version>
</dependency>
四、安装到本地
到 ./target/generated-sources/archetype目录下 执行
mvn install
五、发布到私服
到 ./target/generated-sources/archetype目录下 执行
mvn deploy
以上几个步骤可以写成一个批处理文件一起来处理 请看我的第二篇文章 juejin.cn/post/712046…
六、新建项目
新建一个组件项目:
mvn archetype:generate -DgroupId=com.gisquest -DartifactId=component-test -Dpackage=com.gisquest.component.test -DarchetypeGroupId=com.gisquest -DarchetypeArtifactId=gisquest-assist-component-archetype -DarchetypeVersion=1.0-SNAPSHOT -DinteractiveMode=false -DarchetypeCatalog=local -X
DarchetypeCatalog=local,代表从本地仓库创建项目,如果要从私服创建项目,请改为:-DarchetypeRepository=私服地址
关于不能从私服中拉取项目,请看此文章的方法二: blog.csdn.net/qq_36669347…