背景 经常使用同一套类似的工程结构,就想着能不能自动构建,不用每次都进行工程结构的拷贝,另外呢也是想建立一套项目工程结构的规范,运用技术代替人工
利用maven 的archtype这些都可以实现
1.构建通用的maven 项目 如:
2.在maven pom.xml中添加
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>3.0.0</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>
</pluginManagement>
3.项目根目录下,执行
mvn archetype:create-from-project
4.进入target/generated-sources/archetype,真正起作用的其实就是它
修改相应的pom.xml文件
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
5.在target/generated-sources/archetype目录下,执行
mvn install
插件打入到本地。若要打入私服可执行 mvn deploy
6.在idea中加入maven archtype
7.想要在idea中删除自己刚才添加的archtype mac 中进入
cd /Users/iss/Library/Caches/IntelliJIdea2018.3/Maven/Indices
vim UserArchetypes.xml
将相应的插件直接删除即可 如: