来自父 POM 的 Maven PluginManagement 变量绑定
Maven PluginManagement Variable Binding from Parent POM
你能帮我理解为什么我不能把我的 <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
但随后插件显示解析为不正确的工件:
[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
我怀疑问题是由于托管插件上的继承变量被绑定时引起的,但我找不到任何 Apache Maven 对 "binding order" 关于父 POM 上 <pluginMangement>
的引用。
为了让 os.detected.classifier
在使用 os-maven-plugin
时正确解析,您需要将其用作插件而不是扩展。出于某种原因,如果您将它用作父 POM 中的扩展,它将解析为该父 POM 所编译的平台。请注意确保 none 的依赖项继承自将 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>
你能帮我理解为什么我不能把我的 <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
但随后插件显示解析为不正确的工件:
[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
我怀疑问题是由于托管插件上的继承变量被绑定时引起的,但我找不到任何 Apache Maven 对 "binding order" 关于父 POM 上 <pluginMangement>
的引用。
为了让 os.detected.classifier
在使用 os-maven-plugin
时正确解析,您需要将其用作插件而不是扩展。出于某种原因,如果您将它用作父 POM 中的扩展,它将解析为该父 POM 所编译的平台。请注意确保 none 的依赖项继承自将 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>