如果在 Maven 3.x 中设置了系统属性 id,如何运行 exec-maven-plugin?

发布于 2025-01-06 03:01:12 字数 439 浏览 3 评论 0原文

如果设置了系统属性,我想运行“exec-maven-plugin”。如何在 Maven 3.x 中完成此操作?

例如,给定:

mvn clean install -DrunTheExec="yes"

那么我该如何实现这个逻辑:

<!-- if $(runTheExec) == yes then run this plugin -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            ...
        </plugin>

I want to run the 'exec-maven-plugin' if a system property is set. How do I accomplish this in Maven 3.x?

For example, given:

mvn clean install -DrunTheExec="yes"

Then how can I implement this logic:

<!-- if $(runTheExec) == yes then run this plugin -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            ...
        </plugin>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧时模样 2025-01-13 03:01:12

我正要添加与 Johnathon 相同的建议,但使用配置文件略有不同。

<profiles>
  <profile>
    <id>runTheExec</id>
    <activation>
      <activeByDefault>false</activeByDefault>
    </activation>
    <build>
      <plugins>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
    ...

然后激活它:

mvn clean install -PrunTheExec

I was just about to add the same suggestion as Johnathon, but using the profile a little differently.

<profiles>
  <profile>
    <id>runTheExec</id>
    <activation>
      <activeByDefault>false</activeByDefault>
    </activation>
    <build>
      <plugins>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
    ...

then to activate it:

mvn clean install -PrunTheExec
℡Ms空城旧梦 2025-01-13 03:01:12

您需要在 pom 中定义一个配置文件,并在其中定义插件。在您的示例中,这将是:

<profiles>
  <profile>
    <activation>
      <property>
        <name>runTheExec</name>
        <value>yes</value>
      </property>
    </activation>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        ...
      </plugin>
    </plugins>
  </profile>
</profiles>

You'll need to define a profile in your pom, with the plugin defined inside of it. In your example, this would be:

<profiles>
  <profile>
    <activation>
      <property>
        <name>runTheExec</name>
        <value>yes</value>
      </property>
    </activation>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        ...
      </plugin>
    </plugins>
  </profile>
</profiles>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文