Maven插件中的执行和配置之间有什么区别

Maven插件中的执行和配置之间有什么区别

本文介绍了Maven插件中的执行和配置之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了此描述,但没有找到似乎很全面.有人可以详细解释一下Maven插件中的executionsconfigurations有什么区别吗?

I found this description but it does not seem comprehensive. Could someone explain in detail what is the difference between executions and configurations in a maven plugin?

推荐答案

<execution>导致插件在maven构建生命周期内(即在构建期间)执行. <configuration>允许您配置插件在执行期间的行为.许多Maven插件提供了有关其配置选项的文档,例如 maven-compiler-plugin .

An <execution> causes the plugin to be executed during the maven build lifecycle, i.e. during your build. The <configuration> allows you to configure the plugin for how it should behave during execution. Many Maven plugins provide documentation about their configuration options, e.g. the maven-compiler-plugin.

您可以在<plugin>级别或<execution>级别上定义<configuration>.前者对所有执行都全局有效,后者特定于执行.

You can define <configuration>s on the <plugin> level or the <execution> level. The former is globally valid for all executions, the latter is specific to the execution.

用于全局特定于执行的配置的示例:

假设您必须使用Java 1.7编译项目,但您想尽早采用Java 9 Jigsaw 功能,然后将module-info.java添加到您的项目中.此Java文件将无法使用源代码级别1.7进行编译.您可以做的是定义maven-compiler-plugin的两个执行,一个执行以源级别1.7编译除module-info.java之外的所有内容,另一个执行仅以源级别1.9编译module-info.java的所有执行:

Suppose, you have to compile your project with Java 1.7 but you want to early adopt Java 9 Jigsaw features and add a module-info.java to your project. This Java file will not compile using source level 1.7. What you can do is define two executions of the maven-compiler-plugin, one that compiles everything except module-info.java with source level 1.7 and one that does only compile module-info.java with source level 1.9:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.3</version>

  <!-- Global plugin configuration for source and target levels. -->
  <configuration>
    <source>1.7</source>
    <target>1.7</target>
  </configuration>

  <executions>
    <!-- Compile all code except module-info.java with the configured source level -->
    <execution>
      <id>default-compile</id>
      <phase>compile</phase>
      <goals>
        <goal>compile</goal>
      </goals>
      <configuration>
        <excludes>
          <exclude>module-info.java</exclude>
        </excludes>
      </configuration>
    </execution>

    <!-- Compile module-info.java with source level 1.9 -->
    <execution>
      <id>compile-module-info-java</id>
      <phase>compile</phase>
      <goals>
        <goal>compile</goal>
      </goals>
      <configuration>
        <source>1.9</source>
        <target>1.9</target>
        <includes>
          <include>module-info.java</include>
        </includes>
      </configuration>
    </execution>
  </executions>
</plugin>

这篇关于Maven插件中的执行和配置之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 05:31