Maven插件-将参数传递到生命周期阶段
我们有一个定制的maven插件,它为我们的项目生成一些代码工件。插件已经像这样配置了生命周期,“生成资源”阶段调用了我们的自定义类Maven插件-将参数传递到生命周期阶段,maven,maven-3,maven-plugin,Maven,Maven 3,Maven Plugin,我们有一个定制的maven插件,它为我们的项目生成一些代码工件。插件已经像这样配置了生命周期,“生成资源”阶段调用了我们的自定义类 <?xml version="1.0" encoding="UTF-8"?> <component-set> <components> <component> <role>org.apache.maven.lifecycle.mapping.Lifecycle
<?xml version="1.0" encoding="UTF-8"?>
<component-set>
<components>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>zip</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
<configuration>
<phases>
<generate-resources>com.b.e:productconfig-maven-plugin:generate</generate-resources>
<package>com.b.e:productconfig-maven-plugin:zip</package>
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
</phases>
</configuration>
</component>
</components>
</component-set>
有人知道如何将参数正确地传递到生命周期阶段吗?有两个问题的要求基本相同,但都没有答案:
component.xml
中的声明指定哪个目标绑定到生命周期的某个阶段,即生命周期映射。换言之,在我的理解中:
- 这是关于如果在构建运行期间通过了一个阶段,将执行什么
- 这不是怎么做到的
映射
,其中键表示阶段,因此根本不可能无法找到错误消息中的目标'generate-Dmojo.param=A'
,它告诉我目标部分的完整字符串被视为目标名称,没有应用进一步的参数提取:
您可以在目标之间加一个逗号,这在Maven 3.6.1上当然有效,但我不能说这是否是一个新特性。i、 e:
<package>org.apache.maven.plugins:maven-jar-plugin:jar,org.expath.pkg:expath-pkg-maven-plugin:pkg</package>
您还需要将plexus元数据插件添加到pom.xml中的构建插件中:
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<version>2.0.0</version>
<executions>
<execution>
<goals>
<goal>generate-metadata</goal>
</goals>
</execution>
</executions>
</plugin>
构建后,我生成的target/classes/META-INF/plexus/components.xml
如下所示:
<component-set>
<components>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>xar</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>xar</type>
<extension>xar</extension>
<packaging>xar</packaging>
</configuration>
</component>
</components>
</component-set>
<component-set>
<components>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>xar</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>xar</type>
<extension>xar</extension>
<packaging>xar</packaging>
</configuration>
</component>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>xar</role-hint>
<implementation>org.expath.pkg.maven.PkgLifecycleMapping</implementation>
<description>EXPath Pkg Lifecycle Mapping</description>
<isolated-realm>false</isolated-realm>
</component>
</components>
</component-set>
org.apache.maven.artifact.handler.ArtifactHandler
沙尔
org.apache.maven.artifact.handler.DefaultArtifactHandler
沙尔
沙尔
沙尔
org.apache.maven.lifecycle.mapping.LifecycleMapping
沙尔
org.expath.pkg.maven.PkgLifecycleMapping
EXPath-Pkg生命周期映射
假的
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<version>2.0.0</version>
<executions>
<execution>
<goals>
<goal>generate-metadata</goal>
</goals>
</execution>
</executions>
</plugin>
<component-set>
<components>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>xar</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>xar</type>
<extension>xar</extension>
<packaging>xar</packaging>
</configuration>
</component>
</components>
</component-set>
<component-set>
<components>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>xar</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>xar</type>
<extension>xar</extension>
<packaging>xar</packaging>
</configuration>
</component>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>xar</role-hint>
<implementation>org.expath.pkg.maven.PkgLifecycleMapping</implementation>
<description>EXPath Pkg Lifecycle Mapping</description>
<isolated-realm>false</isolated-realm>
</component>
</components>
</component-set>