Maven构建本地骨架项目archetype并发布到私服

我们两清 提交于 2020-08-11 06:33:59

一、创建符合自己规范的多模块的maven项目

二、在项目根pom文件中添加maven archetype插件

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-archetype-plugin</artifactId>
        <version>3.0.1</version>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.6.1</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.0.2</version>
        <configuration>
            <encoding>UTF-8</encoding>
        </configuration>
    </plugin>
</plugins>

三、创建archetype到本地仓库

打开IDEA底部终端控制台, CD到项目根目录执行命令

mvn archetype:create-from-project 

四、生成archetype模板

进入archetype目录

cd target/generated-sources/archetype/
mvn install

生成archetype-catalog.xml文件

mvn archetype:crawl

执行以上命令后在本地仓库的根目录中会生成archetype-catalog.xml文件

archetype的内容如下,其中artifactId和groupId待会我们生成的时候要用到

<?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.generated.boot</groupId>
      <artifactId>generated-archetype</artifactId>
      <version>1.0-SNAPSHOT</version>
      <description>generated</description>
    </archetype>
    <archetype>
      <groupId>org.apache.maven.archetypes</groupId>
      <artifactId>maven-archetype-quickstart</artifactId>
      <version>1.1</version>
      <description>quickstart</description>
    </archetype>
  </archetypes>
</archetype-catalog>

五、打开项目目录下的target\generated-sources\archetype\pom.xml文件,添加distributionManagement配置,然后 mvn deploy

  <distributionManagement>
    <repository>
      <id>nexus-releases</id>
      <name>Nexus Release Repository</name>
      <url>http://nexus.***.com:8089/nexus/content/groups/public/</url>
    </repository>
    <snapshotRepository>
      <id>nexus-snapshots</id>
      <name>Nexus Snapshot Repository</name>
      <url>http://nexus.***.com:8089/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
  </distributionManagement>
</project>

milian-archetype\target\generated-sources\archetype>mvn deploy

提示build success的话,你的archetype就上传到服务器了,默认的artifactId就是原来项目的artifactId加上-archetype

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!