骨架

maven骨架是一种快速生成模板项目的方法,这里记录创建、使用的过程

step1 从模板中骨架抽离

首先我们可以使用以下命令对一个模板项目进行骨架抽离工作。
所谓骨架抽离,其实就是将包名、groupId、artifactId、version参数化,抽离出一个用占位符号代替的工程。
mvn archetype:create-from-project

骨架_第1张图片
演示目录

该命令会将以上内容存入target.generated-sources.archetype目录中

骨架_第2张图片
产生抽离工程目录结构

这里有多个pom文件

  • 第一个pom文件内容如下


  4.0.0

  com.jikee.template
  template-boot-single-archetype
  1.0-SNAPSHOT
  maven-archetype

  template-boot-single-archetype

  
    
      
        org.apache.maven.archetype
        archetype-packaging
        3.0.1
      
    

    
      
        
          maven-archetype-plugin
          3.0.1
        
      
    
  

  Parent pom providing dependency and plugin management for applications
        built with Maven

  https://projects.spring.io/spring-boot/#/spring-boot-starter-parent/template-boot-single

  
    
      Pivotal
      [email protected]
      Pivotal Software, Inc.
      http://www.spring.io
    
  

  
    
      Apache License, Version 2.0
      http://www.apache.org/licenses/LICENSE-2.0
    
  

  
    https://github.com/spring-projects/spring-boot/spring-boot-starter-parent/template-boot-single
  


这里注意下
maven-archetype
可以看到这个文件是用来做骨架的pom文件,而不是原文件

  • 第二个pom文件内容如下


    4.0.0

    ${groupId}
    ${artifactId}
    ${version}
    
        org.springframework.boot
        spring-boot-starter-parent
        2.0.2.RELEASE
    

    
        UTF-8
        UTF-8
        1.8
        2.0.2.RELEASE
        1.3.1
        1.1.10
    



    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            ${mybatis-starter.version}
        
        
            com.alibaba
            druid-spring-boot-starter
            ${druid-starter.version}
        
        
            org.springframework.boot
            spring-boot-starter-freemarker
        
        
            org.springframework.boot
            spring-boot-starter-validation
        
        
            mysql
            mysql-connector-java
            5.1.36
        
        
            org.projectlombok
            lombok
            1.16.8
        

        
            com.alibaba
            fastjson
            1.2.54
        
    
    
        
            nexus-releases
            http://frps:8081/nexus/content/repositories/releases/
        
    
    
        
            nexus-releases
            Nexus Release Repository
            http://frps:8081/nexus/content/repositories/releases/
        
        
            nexus-snapshots
            Nexus Snapshot Repository
            http://frps:8081/nexus/content/repositories/snapshots/
        

    
    
        
            
                org.apache.maven.archetype
                archetype-packaging
                3.0.1
            
        
        
            
                
                    org.apache.maven.plugins
                    maven-archetype-plugin
                    3.0.1
                
            
        
    



注意这里

   ${groupId}
    ${artifactId}
    ${version}

可以看到一件被抽离了

step2 安装到本地 或者发布到远程

在target.generated-sources.archetype目录中使用以下命令 安装到本地和发布到远程
mvn archetype:install
mvn deploy
注意 mvn deploy 需要在target.generated-sources.archetype.pom.xml文件中指定发布源


        
            nexus-releases
            Nexus Release Repository
            http://frps:8081/nexus/content/repositories/releases/
        
        
            nexus-snapshots
            Nexus Snapshot Repository
            http://frps:8081/nexus/content/repositories/snapshots/
        

    

step3 使用

在任意位置 使用 mvn archetype:generate来弹出创建目录,选择刚刚建立的模板,输入提示的包名、groupId、artifactId、version信息即可创建

goodluck

扩展

元数据配置文件archetype-metadata.xml



  
    
      src/main/java
      
        **/*.java
      
    
    
      src/main/resources
      
        **/*.xml
        **/*.html
      
    
    
      src/main/resources
      
        **/*.yml
      
    
    
      
      
        README.md
        .gitignore
      
    
  


扩展阅读

https://maven.apache.org/archetype/archetype-models/archetype-descriptor/archetype-descriptor.html
https://www.cnblogs.com/wdas-87895/p/6290912.html

你可能感兴趣的:(骨架)