java - Maven Plugin管理来自父 POM 的变量绑定(bind)

标签 java maven plugins maven-plugin grpc-java

你能帮我理解为什么我不能把我的<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>

<pluginMangement>配置

(注动态<pluginArtifact>)

<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

但随后插件显示解析为不正确的 Artifact :

[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

我怀疑这个问题是由于托管插件上的继承变量被绑定(bind)时造成的,但我找不到任何关于 <pluginMangement> 的“绑定(bind)顺序”的 Apache Maven 引用。在父 POM 上。

最佳答案

为了在使用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>

关于java - Maven Plugin管理来自父 POM 的变量绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57775532/

相关文章:

eclipse - 在 eclipse 上导入并运行 WAR

java - 在 Tomcat 上部署后显示应用程序上下文路径

java - 最佳实践 : Versioning and releases in multiprojects

Maven网站插件不包括Jacoco报告

jquery - 当 scrollTop 等于某物时,启动一个函数,但只有一次

java - 如何用引号在 Thymeleaf 问题中添加 <i class ="something"></i>

java - Spring安全+LDAP。无法调试

java - JSF 国际化 f :loadbundle or through faces-config: Performance point

java - 从 gradle 任务执行 commons-math Java 类

java - 从录音中检测音符