SHA*_*ANK 5 java yahoo automation image-compression maven
我想在maven build中集成Yahoo smush.it来自动化构建本身的图像压缩.
任何人都可以帮我这样做吗?
我也对其他图书馆开放.[后端是Java.]
您是否考虑过编写一个小型 Maven 插件来自己自动化执行此操作?该插件 API 很棒,而且非常简单 - 您可以在这里查看。基本上,您将创建一个插件项目,它接受一些 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.
}
}
Run Code Online (Sandbox Code Playgroud)
然后,在pom.xml希望使用您新编写的 mojo 的 中,在<plugins>下面的标签中按如下方式使用它<build>:
<plugin>
<groupId>com.stackoverflow</groupId>
<artifactId>smush-it-maven-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<executions>
<execution>
<id>compress</id>
<goals>
<goal>compress</goal>
</goal>
<configuration>
<images>
<image>${project.build.directory}/../images/1.png</image>
<image>${project.build.directory}/../images/2.png</image>
<image>${project.build.directory}/../images/3.png</image>
</images>
<destination>${project.build.directory}/../src/main/resources/compressed/
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
然后,您可以预期这三个图像将保存到压缩资源文件夹中,然后在稍后的生命周期阶段将其打包。显然,关于图像的来源和保存位置有很大的灵活性。但魔力本身非常简单,这正是您如何自动化特定于应用程序的任务以使用 Maven。