【问题标题】:exec-maven-plugin: Can I run exec:exec goal without first running the toolchains:toolchain goal?exec-maven-plugin:我可以在不先运行 toolchains:toolchain 目标的情况下运行 exec:exec 目标吗?
【发布时间】:2021-01-16 09:48:35
【问题描述】:

我继承了一个只能在 Java 1.8 中编译和运行的应用程序。因为我不想让 Java 1.8 成为我机器上的主要 jvm,所以我觉得管理它的最佳方法是通过 Maven 工具链。配置 maven-compiler-plugin 非常简单,但我还想添加通过 Maven 执行服务的功能,以便利用我为 1.8 配置的工具链。

挑战在于我似乎无法让 exec-maven-plugin 使用文档中的工具链。根据文档,我认为 exec-maven-plugin 会根据需要使用 maven-toolchains-plugin。但是,为了让exec:exec 使用正确的工具链,我必须使用:

mvn toolchains:toolchain exec:exec

这可行,但documentation 让我认为工具链会自动配置,而无需我执行toolchains:toolchain 目标。

pom.xml

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-toolchains-plugin</artifactId>
      <executions>
        <execution>
          <goals>
            <goal>toolchain</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <toolchains>
          <jdk>
            <version>1.8</version>
          </jdk>
        </toolchains>
      </configuration>
    </plugin>
        
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <configuration>
        <executable>java</executable>
        <arguments>
          <argument>-classpath</argument>
          <classpath></classpath>
          <argument>com.my.Main</argument>
        </arguments>
      </configuration>
    </plugin>
  </plugins>
</build>

工具链.xml

<?xml version="1.0" encoding="UTF8"?>
<toolchains>
  <toolchain>
    <type>jdk</type>
    <provides>
      <id>1.8</id>
      <version>1.8</version>
    </provides>
    <configuration>
      <jdkHome>/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home</jdkHome>
    </configuration>
  </toolchain>
</toolchains>

附加说明:我还尝试使用以下配置将 exec-maven-plugin 配置为在 exec:java 上运行:

<configuration>
  <mainClass>com.my.Main</mainClass>
</configuration>

但这不起作用,即使是 mvn toolchains:toolchain exec:java

有没有办法配置它,以便我只需要运行mvn exec:execmvn exec:java

【问题讨论】:

    标签: java maven toolchain maven-exec-plugin


    【解决方案1】:

    我认为答案是您必须确保 toolchains 插件本身是您构建的一部分。或者这就是the relevant documentation seems to say。 (我在上面看到你有这个;我的意思是,是的,这是必需的。)

    【讨论】:

    • 不是我想要的答案,但它似乎是正确的答案。 :)
    猜你喜欢
    • 2013-12-03
    • 2016-11-24
    • 1970-01-01
    • 1970-01-01
    • 2012-11-13
    • 1970-01-01
    • 2019-10-16
    • 2020-08-07
    • 1970-01-01
    相关资源
    最近更新 更多