Previous # SpringBoot development, this package is enough! This article is based on the last output of springboot foundation package dependence, only one command, help you generate scaffolding with basic functions, so that you no longer need CTRL + C, CTRL + V to create the project, However, you no longer have to worry about conflicts and other issues that arise from reframing
The github address of this project is github.com/chenxuancod…
What is the archetype
Archetype, also known as archetype, is a Maven plugin, or project template, that creates a project structure from the template.
Custom archeType
- Create a normal Maven project
- Defining project templates
In archetype-Resources, is the template for the scaffolding to be generated. Whatever you think a universal scaffolding function requires just throw it in. I integrate base dependency here, so I need to do some configuration of Mybatis- Plus pagination, Swagger configuration and so on. In addition, I provide a generate.java for generating code In short, template content is added on demand
- Defining template parameters
META-INF/archetype-metadata
<arche-type-descriptor name="archetype">
<fileSets>
<fileSet filtered="true" encoding="UTF-8" packaged="true">
<directory>src/main/java</directory>
<includes>
<include>/ *. * * *</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="true">
<directory>src/test/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="false">
<directory>src/main/resources</directory>
<includes>
<include>**/*.yml</include>
</includes>
</fileSet>
</fileSets>
<requiredProperties>
<requiredProperty key="port"/>
<requiredProperty key="groupId">
<defaultValue>com.sleeper</defaultValue>
</requiredProperty>
<requiredProperty key="artifactId">
<defaultValue>demo</defaultValue>
</requiredProperty>
<requiredProperty key="package">
<defaultValue>${groupId}.${artifactId}</defaultValue>
</requiredProperty>
<requiredProperty key="version">
<defaultValue>1.0.0 - the SNAPSHOT</defaultValue>
</requiredProperty>
</requiredProperties>
</arche-type-descriptor>
Copy the code
The requiredProperties node defines variable parameters for the project template, which can be passed in when the mvnarchetype:generate command generates scaffolding.
Generating project
- Compile archetype project using Maven Install
- Use the MVN archetype command to generate the project
MVN archetype: generate-darchetypegroupid =com.sleeper -DarchetypeArtifactId=archetype -DarchetypeVersion= 1.0.0-snapshot -DgroupId=com.sleeper -DartifactId=demo -Dport=8888Copy the code