自定义archetype骨架
搭建maven模板项目
添加插件
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>3.2.1</version>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>3.0.1</version>
</extension>
</extensions>
</build>
创建archetype骨架
mvn clean archetype:create-from-project
target目录下会有generated-sources目录,generated- sources/archetype/src/main.resource/META_INF.maven下会有一个archetype-metadata.xml文件,这里是可以配置那些资源会被包含在骨架中,那些不会包含在骨架中。
注意:替换模块名称,取根据archetype骨架创建项目时候的artifactId进行填充
(1)更换模块名:rootArtifactId__这里是双下划线( _ rootArtifactId _ )
(2) 更改archetype-metadata.xml配置占位符:名称${rootArtifactId}和包__rootArtifactId
在 target/generated-sources/archetype/src/main/resources/META-INF.maven/ 目录下 更改archetype-metadata.xml 如下图
(3)更改pox文件的groupId和artifactId
(4)分别更改各个模块的pom文件>
g
r
o
u
p
I
d
和
{groupId}和
groupId和{rootArtifactId},如下所示
(5)更改bootstrap.yml文件的spring:application:name为${artifactId}
安装archetype到本地
(1)进入target/generated-sources/archetype目录
cd target/generated-sources/archetype/
(2)进行安装
mvn clean install
构建成功可以在info指示的目录下找到骨架的jar包。
在本地仓库生成骨架坐标信息
mvn archetype:crawl
maven本地仓库下就会生成一个archetype-metadata.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.tree.archetype</groupId>
<artifactId>tree-archetype.all-archetype</artifactId>
<version>1.0-SNAPSHOT</version>
<description>tree-archetype.all</description>
</archetype>
<archetype>
<groupId>repository.org.apache.maven.archetypes</groupId>
<artifactId>maven-archetype-quickstart</artifactId>
<version>1.3</version>
<description>quickstart</description>
</archetype>
<archetype>
<groupId>za.co.absa.hyperdrive</groupId>
<artifactId>component-archetype_2.12</artifactId>
<version>4.7.0</version>
<description>archetype</description>
</archetype>
</archetypes>
</archetype-catalog>