您是否考虑过编写一个小型Maven插件来自动完成此操作?插件API非常棒,非常简单 – 您可以查看
here.基本上,您将创建一个插件项目,它接受一些XML参数并为您执行转换:
@Mojo(name = "compress", defaultPhase = "compile")
public class SmushItCompressMojo extends AbstractMojo {
@Parameter(property = "images")
String[] images;
@Parameter(property = "destination")
String destination;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
// Validate your inputs.
// For each image file:
// Compress it using a request to smush.it.
// Save the compressed image to the destination file.
// Report any errors/success.
}
}
然后,在希望使用新编写的mojo的pom.xml中,在< plugins>中使用它,如下所示. < build>下的标记:
com.stackoverflow
smush-it-maven-plugin
1.0.0-SNAPSHOT
compress
compress
${project.build.directory}/../images/1.png
${project.build.directory}/../images/2.png
${project.build.directory}/../images/3.png
${project.build.directory}/../src/main/resources/compressed/
然后,您可以将三个图像保存到压缩资源文件夹中,然后将在后续生命周期阶段打包.显然,这里有很多灵活性来确定图像来自哪里并得到保存.但是mojo本身非常简单,这正是您使用Maven自动执行特定于应用程序的任务的方式.