Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven插件-将参数传递到生命周期阶段_Maven_Maven 3_Maven Plugin - Fatal编程技术网

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

我们有一个定制的maven插件,它为我们的项目生成一些代码工件。插件已经像这样配置了生命周期,“生成资源”阶段调用了我们的自定义类

<?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>