Maven只是一套框架,它的功能基于全部依赖于插件来实现。因此可以通过插件开发来定制Maven。
https://maven.apache.org/guides/plugin/guide-java-plugin-development.html
Maven 官方的插件命名为:maven-<yourplugin>-plugin
第三方插件命名要求为:<yourplugin>-maven-plugin
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.0</version>
</dependency>
<!-- 插件注解 -->
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<packaging>maven-plugin</packaging>
<packaging>maven-plugin</packaging>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<goalPrefix>zzw</goalPrefix>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
1、添加maven-plugin-plugin
插件依赖,这个包可以使插件支持JDK1.8以上的版本;
[Ref] Maven插件开发教程
2、addDefaultImplementationEntries
会在生成的jar包的META-INF
目录下的MANIFEST.MF
文件里生成版本信息
[Ref] maven项目代码获取<version>版本号(通过jar包获取)
[Ref] Maven maven-jar-plugin 配置详情
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
@Mojo(name = "sayhi")
public class GreetingMojo extends AbstractMojo {
public void execute() throws MojoExecutionException {
getLog().info("Hello, world.");
}
}
Maven - 通过开发插件了解 Maven
Idea开发maven插件
如何开发一个maven插件
Maven插件开发
Error resolving version for plugin ‘XXX‘ from the repositories,Plugin not found in any plugin reposi