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">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.go</groupId>
<artifactId>plugin_demo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.0</version>
</dependency>
<!-- dependencies to annotations -->
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
GreetingMojo.java
package cn.go;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
@Mojo(name = "go")
public class GreetingMojo extends AbstractMojo {
public void execute() throws MojoExecutionException {
getLog().info("Hello, mojo.");
}
}
运行 install
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200916095135506.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3d3cTkyMTIyMA==,size_16,color_FFFFFF,t_70#pic_center)
install 报错
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project plugin_demo: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: Plugin org.apache.maven.plugins:maven-plugin-plugin:3.2 or one of its dependencies could not be resolved: The following artifacts could not be resolved: org.apache.maven.plugin-tools:maven-plugin-tools-annotations:jar:3.2, org.apache.maven.plugin-tools:maven-plugin-tools-api:jar:3.2, org.apache.maven.plugin-tools:maven-plugin-tools-generators:jar:3.2, org.apache.maven.plugin-tools:maven-plugin-tools-java:jar:3.2, org.apache.maven.plugin-tools:maven-plugin-tools-beanshell:jar:3.2, org.apache.maven.plugin-tools:maven-plugin-tools-model:jar:3.2: Failure to find org.apache.maven.plugin-tools:maven-plugin-tools-annotations:jar:3.2 in http://10.129.2.106:8081/nexus/content/groups/public/ was cached in the local repository, resolution will not be reattempted until the update interval of nexus-private has elapsed or updates are forced -> [Help 1]
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200916094011637.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3d3cTkyMTIyMA==,size_16,color_FFFFFF,t_70#pic_center)
- 上图是一个构建的标准生命周期,报错的阶段是图中圈出的节点;
- 解决方法(2个方法任意一个都行,不是两个步骤):
配置代理
<proxies>
<!-- proxy
| Specification for one proxy, to be used in connecting to the network.
|
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
-->
<!-- <proxy> -->
<!-- id 代理的名称(随便设) -->
<!-- <id>optional</id> -->
<!-- true 表示生效 -->
<!-- <active>true</active> -->
<!-- 协议 -->
<!-- <protocol>http</protocol> -->
<!-- 本机上网用户名及密码,如果没有,请注释或者是删除 -->
<!-- <username>*******.ex</username> -->
<!-- <password>a*169646</password> -->
<!-- 公司上网使用ip及端口,即代理,这里替换成相对应的ip和端口 -->
<!-- <host>127.0.0.1</host> -->
<!-- <port>8888</port> -->
<!-- 填写不用代理的地址,以竖线|分割多个地址,一般填写本地Maven仓库地址 -->
<!-- <nonProxyHosts>local.net</nonProxyHosts> -->
<!-- </proxy> -->
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<host>127.0.0.1</host>
<port>8888</port>
<nonProxyHosts>local.net</nonProxyHosts>
</proxy>
</proxies>
pom.xml 中添加配置
<build>
<plugins>
<plugin>
<groupId>cn.go</groupId>
<artifactId>plugin_demo</artifactId>
<version>1.0-SNAPSHOT</version>
</plugin>
</plugins>
</build>
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200916095324647.png#pic_center)
- 运行 goal
mvn cn.go:plugin_demo:1.0-SNAPSHOT:go
;效果如图:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200916095702956.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3d3cTkyMTIyMA==,size_16,color_FFFFFF,t_70#pic_center)