1. <?xml version="1.0" encoding="UTF-8"?>
    2. <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3. xmlns="http://maven.apache.org/POM/4.0.0"
    4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    5. <modelVersion>4.0.0</modelVersion>
    6. <groupId>mojo.test</groupId>
    7. <artifactId>mojoTest-maven-plugin</artifactId>
    8. <version>1.0.0</version>
    9. <packaging>maven-plugin</packaging>
    10. <dependencies>
    11. <dependency>
    12. <groupId>org.apache.maven</groupId>
    13. <artifactId>maven-plugin-api</artifactId>
    14. <version>3.8.4</version>
    15. </dependency>
    16. <dependency>
    17. <groupId>org.apache.maven.plugin-tools</groupId>
    18. <artifactId>maven-plugin-annotations</artifactId>
    19. <version>3.6.4</version>
    20. </dependency>
    21. <dependency>
    22. <groupId>cn.hutool</groupId>
    23. <artifactId>hutool-all</artifactId>
    24. </dependency>
    25. </dependencies>
    26. <build>
    27. <plugins>
    28. <plugin>
    29. <artifactId>maven-plugin-plugin</artifactId>
    30. <version>3.6.0</version>
    31. <executions>
    32. <execution>
    33. <id>default-addPluginArtifactMetadata</id>
    34. <phase>package</phase>
    35. <goals>
    36. <goal>addPluginArtifactMetadata</goal>
    37. </goals>
    38. </execution>
    39. <execution>
    40. <id>default-descriptor</id>
    41. <phase>process-classes</phase>
    42. <goals>
    43. <goal>descriptor</goal>
    44. </goals>
    45. </execution>
    46. </executions>
    47. </plugin>
    48. </plugins>
    49. </build>
    50. </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>