现在很多都不用ant这样的古老构建工具了,用maven如何自动构建插件呢.下面举个栗子:
-
在plugins下创建一个叫做myplugin的module:
2.myplugin下的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>plugins</artifactId>
<groupId>org.igniterealtime.openfire</groupId>
<version>4.6.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>myplugin</artifactId>
<build>
<sourceDirectory>src/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
</plugin>
</plugins>
</build>
</project>
-
看看plugins下的pom.xml中的<modules>标签下是否添加了myplugin插件
4.distribution下pom.xml中添加一下代码:
- 添加依赖配置
<artifactItem>
<groupId>com.example</groupId>
<artifactId>myplugin</artifactId>
<classifier>openfire-plugin-assembly</classifier>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}${file.separator}distribution-base${file.separator}plugins</outputDirectory>
<destFileName>MyPlugin.jar</destFileName>
</artifactItem>
如图:
- 添加依赖关系
<dependency>
<groupId>com.example</groupId>
<artifactId>myplugin</artifactId>
<version>${project.version}</version>
<classifier>openfire-plugin-assembly</classifier>
<scope>provided</scope>
</dependency>
好了,构建吧!
先plugin模块,后distribution模块,运行代码
mvn clean
然后
mvn verify
结果