【问题标题】:Maven PluginManagement Variable Binding from Parent POM来自父 POM 的 Maven PluginManagement 变量绑定
【发布时间】:2019-09-03 16:25:21
【问题描述】:

你能帮我理解为什么我不能把我的<pluginMangement> 配置放在我的父 POM 上吗?

我有这个<pluginMangement> 配置。当它在父 POM 中时,我的构建失败 因为<pluginArtifact> 错误地解析为:

io.grpc:protoc-gen-grpc-java:1.23.0:exe:linux-x86_64

当它在我的 POM 中时,<pluginArtifact> 正确解析为

io.grpc:protoc-gen-grpc-java:1.23.0:exe:osx-x86_64

在我的本地 POM 中,我使用了这个构建扩展:

<build>
    <extensions>
        <extension>
            <groupId>kr.motd.maven</groupId>
            <artifactId>os-maven-plugin</artifactId>
            <version>1.5.0.Final</version>
        </extension>
    </extensions>

&lt;pluginMangement&gt;配置

(注意动态&lt;pluginArtifact&gt;)

<build>
  <pluginManagement>
    <plugins>
  <plugin>
  <!-- http://os72.github.io/protoc-jar-maven-plugin/run-mojo.html -->
  <groupId>com.github.os72</groupId>
  <artifactId>protoc-jar-maven-plugin</artifactId>
  <version>${protoc-jar-maven-plugin.version}</version>
  <executions>
      <execution>
          <id>generate-sources</id>
          <phase>generate-sources</phase>
          <goals>
              <goal>run</goal>
          </goals>
          <configuration>
              <addProtoSources>all</addProtoSources>
              <includeMavenTypes>direct</includeMavenTypes>
              <includeMavenTypes>transitive</includeMavenTypes>
              <includeDirectories>
                  <include>src/main/proto</include>
              </includeDirectories>
              <inputDirectories>
                  <include>src/main/proto</include>
              </inputDirectories>
              <protocArtifact>
                  com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}
              </protocArtifact>
              <outputTargets>
                  <outputTarget>
                      <type>java</type>
                  </outputTarget>
                  <outputTarget>
                      <type>grpc-java</type>
                      <pluginArtifact>
                          io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}
                      </pluginArtifact>
                  </outputTarget>
              </outputTargets>
          </configuration>
      </execution>
  </executions>
</plugin>

当配置在父节点上时,os.detected.classifier 在构建开始时显示正确:

[INFO] ------------------------------------------------------------------------
[INFO] Detecting the operating system and CPU architecture
[INFO] ------------------------------------------------------------------------
[INFO] os.detected.name: osx
[INFO] os.detected.arch: x86_64
...
[INFO] os.detected.classifier: osx-x86_64

但随后插件显示解决了不正确的工件:

[INFO] --- protoc-jar-maven-plugin:3.8.0:run (generate-sources) @ recipe-order-processor ---
[INFO] Resolving artifact: com.google.protobuf:protoc:3.9.0:exe:linux-x86_64, platform: osx-x86_64

我怀疑问题是由于托管插件上的继承变量被绑定,但我在父 POM 上找不到任何 Apache Maven 对&lt;pluginMangement&gt; 的“绑定顺序”的引用。

【问题讨论】:

  • 另外,如果我运行:mvn clean compile ...构建在protoc-jar-maven-plugin 处失败。如果我运行:mvn protoc-jar,那么插件会正确解析。
  • 我还在protoc-jar-maven-plugin处放了一个断点;当它被调用时,来自插件&lt;configuration&gt; 的变量已被解析/绑定到(不正确的)linux-x86_64 arch。

标签: java maven plugins maven-plugin grpc-java


【解决方案1】:

为了在使用os-maven-plugin 时正确解析os.detected.classifier,您需要将其用作插件而不是扩展。出于某种原因,如果您将其用作父 POM 中的扩展,它将解析为编译该父 POM 的平台。请注意确保没有任何依赖项继承自将 os-maven-plugin 定义为扩展的父 pom。

文档没有提到将父 POM 继承作为将 os-maven-plugin 配置为插件的原因,但它确实说明了如何使用。

https://github.com/trustin/os-maven-plugin#issues-with-eclipse-m2e-or-other-ides

<plugin>
    <groupId>kr.motd.maven</groupId>
    <artifactId>os-maven-plugin</artifactId>
    <version>1.6.1</version>
    <executions>
        <execution>
            <phase>initialize</phase>
            <goals>
                <goal>detect</goal>
            </goals>
        </execution>
    </executions>
</plugin>

【讨论】:

    猜你喜欢
    • 2011-11-13
    • 1970-01-01
    • 2020-08-19
    • 2015-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-07
    • 2010-12-31
    相关资源
    最近更新 更多