Maven PluginManagement Variable Binding from Parent POM

JJ Zabkar :

Can you help me understand why I cannot put my <pluginMangement> config on my parent POM?

I have this <pluginMangement> config. When it is in the parent POM, my build fails because the <pluginArtifact> incorrectly resolves to:

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

When it is in my POM, the <pluginArtifact> correctly resolves to

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

In my local POM, I use this build extension:

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

<pluginMangement> config

(Note dynamic <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>

When the configuation is on the parent, the os.detected.classifier shows correct at the start of the build:

[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

But then the plugin shows to resolve to the incorrect 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

I suspect the issue is due to when inherited variables on managed plugins are bound, but I can't find any Apache Maven references to "binding order" regarding <pluginMangement> on parent POMs.

Israel Evans :

In order to get os.detected.classifier to resolve correctly when using os-maven-plugin, you need to use it as a plugin not an extension. For some reason, if you use it as an extension in the parent POM, it will resolve to the platform that that parent POM was compiled on. Be careful to be sure that none of you dependencies inherit from a parent pom that defines os-maven-plugin as an extension.

The documentation doesn't mention parent POM inheritance as a reason to configure os-maven-plugin as a plugin, but here is what it does say about how.

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>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=139942&siteId=1