构建出自己的archetype-java脚手架

进公司工作工作发现每个公司都有自己的脚手架来初始化项目,故也想开发一套自己的脚手架进行使用,会整合一些常用的东西,来解放双手

步骤

  1. 创建出正常运行的项目
  2. parent的pom文件中添加插件
<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-archetype-plugin</artifactId>
                <version>3.2.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>
        </plugins>
    </build>
  1. 项目根目录下执行maven命令
mvn archetype:create-from-project
  1. target/generated-sourced/archetype目录下就是我们需要的项目模板
    删除不需要的文件,如idea等文件
  2. 切换到archetype目录执行maven命令,安装到本地
mvn  clean install
  1. 查看本地maven仓库地址,会有一个archetype-catalog.xml文件后打开后会有构建信息如:
	<archetype>

      <groupId>com.yh.zq</groupId>

      <artifactId>project-name</artifactId>

      <version>1.0.0</version>

      <description>desc</description>

    </archetype>
  1. 至此就创建成功了自定义的Archetype,可以通过命令从本地模板创建工程

mvn archetype:generate -DarchetypeCatalog=local

创建步骤:10

1.输入新构建项目的组件id
2. 输入项目名称
3. 输入版本名称
4. 确定基础包
  1. 上传Archetype到私服
    Archetype目录下的pom文件粘贴私服地址

<!--私服配置-->
    <distributionManagement>
        <repository>
            <id>releases</id>
            <name>Nexus Release Repository</name>
            <url>xxxxx</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <name>Nexus Snapshot Repository</name>
            <url>xxxx</url>
        </snapshotRepository>
    </distributionManagement>```
  1. 执行maven部署命令

mvn deploy
  1. 通过本地命令使用脚手架
mvn archetype:generate -DarchetypeCatalog=local
  1. 通过私服使用脚手架
    切记不要使用powerShell打开执行会报错,使用cmd执行即可
    `` The goal you specified requires a project to execute but there is no POM in this directory (E:\ours\demo). Please verify you invoked Maven from the correct directory. -> [Hel
    p 1]```
    两者区别是前者指定了私服地址,后者指定了包名称
mvn archetype:generate -DinteractiveMode=false -DgroupId=com.yh.zq -DartifactId=yh-demo-test -Dversion=1.0-SNAPSHOT -Dpackage=com.zq.yh -DarchetypeGroupId=yhlovezq.top -DarchetypeArtifactId=yh-archetype -DarchetypeVersion=1.0-SNAPSHOT -DarchetypeRepository=http://n.qdedu.cn/nexus/content/repositories/snapshots/
mvn archetype:generate -DgroupId=com.free -DartifactId=demo-t -Dversion=1.0.0 -Dpackage=com.free.demo -DarchetypeGroupId=yhlovezq.top -DarchetypeArtifactId=yh-archetype -DarchetypeVersion=1.0-SNAPSHOT -DinteractiveMode=false

参数说明:
命令参数 介绍
DgroupId 所需生成项目的groupId
DartifactId 所需生成项目的artifactId
Dversion 所需生成项目的version
Dpackage 所需生成项目的包名
DarchetypeGroupId Archetypal模板的groupId
DarchetypeArtifactId Archetypal模板的artifactId
DarchetypeVersion Archetypal模板的version
DarchetypeRepository 私服地址
12. 其他人通过maven命令使用该脚手架时候要么setting文件进行配置要么指定私服地址进行使用

通过idea进行添加的方式不作赘述。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值