菜单

Maven插件教程(1)—clean插件

2019年10月4日 - 皇家赌场系统

能够经过在plugin下参预那几个布局,此时不论强制调用clean照旧机关调用clean,都不会删除target目录了。

当大家调用clean阶段,clean生命周期被电动调用,这几个生命周期独有三个clean的靶子,利用clean插件来产生那一个目标——删除构建文件夹,日常来讲,这些创设文件夹是类别中的target文件夹。

[INFO] Scanning for projects...[INFO] [INFO] ------------------------------------------------------------------------[INFO] Building utils 1.0-SNAPSHOT[INFO] ------------------------------------------------------------------------[INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ utils ---[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 0.207 s[INFO] Finished at: 2017-08-15T15:19:27+08:00[INFO] Final Memory: 7M/123M[INFO] ------------------------------------------------------------------------Process finished with exit code 0

为了兑现那个成效,大家能够在POM文件内出席如下配置:

<configuration> <skip>false</skip> <filesets> <fileset> <directory>${basedir}/report</directory> </fileset> </filesets></configuration>
 <build> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>2.5</version> <executions> <execution> <id>auto-clean</id> <phase>initialize</phase> <goals> <goal>clean</goal> </goals> </execution> </executions> </plugin> </plugins> </build>

当我们创设maven工程的时候,为了不让先前的构建输出影响到此番塑造,日常要求将将先前的塑造文件夹和文件删除。maven中运用clean插件来变成那项职务。不要紧先品尝clean一下maven项目:mvn clean

奇迹,你恐怕会不愿意clean插件删除target目录,怎么落到实处呢?

[INFO] Scanning for projects...[INFO] [INFO] ------------------------------------------------------------------------[INFO] Building utils 1.0-SNAPSHOT[INFO] ------------------------------------------------------------------------[INFO] [INFO] --- maven-clean-plugin:2.5:clean (auto-clean) @ utils ---[INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ utils ---[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent![INFO] Copying 0 resource[INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ utils ---[INFO] Nothing to compile - all classes are up to date[INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ utils ---[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent![INFO] skip non existing resourceDirectory F:\BitBucket\utils\src\test\resources[INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ utils ---[INFO] Nothing to compile - all classes are up to date[INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ utils ---[INFO] No tests to run.[INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ utils ---[INFO] Building jar: F:\BitBucket\utils\target\utils-1.0-SNAPSHOT.jar[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 1.167 s[INFO] Finished at: 2017-08-15T15:28:13+08:00[INFO] Final Memory: 10M/155M[INFO] ------------------------------------------------------------------------

如上配置会在initialize阶段调用clean插件,这几个推行被取名字为auto-clean,也正是其id。

能够发掘,clean在最早化阶段被机关调用了。

说惠氏下,敲入mvn package,能够见到如下结果:

由于clean是单独于default生命周期的,所以clean无法被default生命周期自动调用,因此日常的话必需在default生命周期被调用在此之前调用。有没有法子能够完毕让default生命周期自动调用clean插件来形成clean的对象吗?

<configuration> <skip>true</skip></configuration>

那倘使指望可以删除额外的目录呢?此时能够在configuration中配备filesets,通过这一个布局就足以激增要求非常删除的目录了。

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图