buid-helper-maven-plugin简单使用

简介

官方文档

https://www.mojohaus.org/build-helper-maven-plugin/index.html

常用的Goals

名称 说明
build-helper:add-source 添加一个或者多个目录到POM.
build-helper:add-test-source 添加测试目录到 POM.
build-helper:add-resource 添加资源目录到POM.
build-helper:add-test-resource 添加测试资源目录到POM.
build-helper:attach-artifact 附加要安装和部署的其他部件。
build-helper:maven-version 设置一个包含当前版本的 maven 的属性。
build-helper:regex-property 通过将正则表达式替换规则应用于提供的值来设置属性。
build-helper:regex-properties 通过将正则表达式替换规则应用于提供的值来设置属性.
build-helper:released-version 解决本项目最新发布的版本.
build-helper:parse-version 将版本解析为不同的属性.
build-helper:remove-project-artifact 从本地存储库中删除项目的工件.
build-helper:reserve-network-port 保留随机和未使用的网络端口列表.
build-helper:local-ip 检索当前主机 IP 地址.
build-helper:hostname 检索当前主机名.
build-helper:cpu-count 检索可用 CPU 的数量.
build-helper:timestamp-property 根据当前日期和时间设置属性.
build-helper:uptodate-property 根据文件集的输出相对于其输入是否是最新的来设置属性.
build-helper:uptodate-properties 根据多个文件集的输出相对于它们的输入是否是最新的来设置多个属性.
build-helper:rootlocation 设置定义多模块构建的根文件夹的属性.

简单用法

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.3.0</version>
        <executions>
          <execution>
            <!--id是必须的,常常和goals是一样的-->
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <!--在configuration中设置goals的具体属性-->
            <configuration>
              <!--这些熟悉可以通过文档获得-->
              <sources>

                <source>some directory</source>
                ...
              </sources>
            </configuration>
          </execution>
          <!--在比如下面的,可以获得当前时间-->
          <execution>
            <id>timestamp-property</id>
            <goals>
              <goal>timestamp-property</goal>
            </goals>
              <configuration>
                  <name>current.time</name>
                  <pattern>yyyyMMddHHmmss</pattern>
                  <timeZone>GMT+8</timeZone>
              </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

获得当前时间的那个,可以通过configuration的name在pom的其他地方通过${current.time}来引用当前时间

posted @ 2022-02-10 11:19  bbird2018  阅读(373)  评论(0编辑  收藏  举报