<?xml version="1.0" encoding="UTF-8"?><project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" 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>mojo.test</groupId> <artifactId>mojoTest-maven-plugin</artifactId> <version>1.0.0</version> <packaging>maven-plugin</packaging> <dependencies> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> <version>3.8.4</version> </dependency> <dependency> <groupId>org.apache.maven.plugin-tools</groupId> <artifactId>maven-plugin-annotations</artifactId> <version>3.6.4</version> </dependency> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-plugin-plugin</artifactId> <version>3.6.0</version> <executions> <execution> <id>default-addPluginArtifactMetadata</id> <phase>package</phase> <goals> <goal>addPluginArtifactMetadata</goal> </goals> </execution> <execution> <id>default-descriptor</id> <phase>process-classes</phase> <goals> <goal>descriptor</goal> </goals> </execution> </executions> </plugin> </plugins> </build></project>
package com.genew.plugin;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ZipUtil;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import java.io.File;
@Mojo(name = "mojoTest")
public class MojoTest extends AbstractMojo {
@Parameter
String version;
@Parameter
String basePath;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Log log = getLog();
log.info("Mojo Test.")
File outputFile = new File(basePath + File.separator + "output");
if (outputFile.exists()) {
log.info("Delete output folder.");
FileUtil.del(outputFile);
}
log.info("Create output folder.");
outputFile.mkdir();
log.info("copy file");
File oldFile = new File(basePath + File.separator + "oldFile");
FileUtil.copy(oldFile, outputFile, true);
log.info("rename file");
File newFile = new File(outputFile.getAbsolutePath() + File.separator + "newFile");
newFile = FileUtil.rename(newFile, "newFileR", true);
File serviceFile = new File(newNuMaxCloud9000File.getAbsolutePath() + File.separator + "Services");
log.info("Zip folder.");
File newZipFile = new File(outputFile.getAbsolutePath() + File.separator + "newFile.zip");
ZipUtil.zip(newFile.getAbsolutePath(), newZipFile.getAbsolutePath(), true);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>mojo.test</groupId>
<artifactId>mojoInvoke</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>mojo-test</groupId>
<artifactId>mojoTest-maven-plugin</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>mojo-test</groupId>
<artifactId>mojoTest-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>mojoTest</id>
<phase>package</phase>
<goals>
<goal>mojoTest</goal>
</goals>
<configuration>
<version>${project.version}</version>
<basePath>.</basePath>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>