您可以使用Beanshell编写 Maven 插件。
<dependencies> <dependency> <groupId>org.apache-extras.beanshell</groupId> <artifactId>bsh</artifactId> <version>2.0b6</version> </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-script-beanshell</artifactId> <version>3.6.4</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-plugin-plugin</artifactId> <version>3.6.4</version> <dependencies> <dependency> <groupId>org.apache.maven.plugin-tools</groupId> <artifactId>maven-plugin-tools-beanshell</artifactId> <version>3.6.4</version> </dependency> </dependencies> </plugin> </plugins> </build>
Beanshell mojo 使用与带有 javadoc 标签的 Java mojo 相同的 javadoc 标签。
示例脚本内容:
/** * Touches a test file. * * @goal touch * @requiresDependencyResolution=test * @deprecated Don't use! * @since 1.2 */ import org.apache.maven.plugin.Mojo; import org.apache.maven.script.beanshell.BeanshellMojoAdapter; import org.codehaus.plexus.util.FileUtils; execute() { logger.info( "Executing beanshell mojo..." ); FileUtils.fileWrite( outDir + "/" + name, "This is a Beanshell test" ); } /** * Output directory for files. * * @parameter expression="${project.build.directory}" * @required */ setOutDir( file ) { outDir = file; } /** * * * @parameter expression="${name}" * @required */ setName( name ) { name = name; } return new BeanshellMojoAdapter( (Mojo) this, this.interpreter );