简体   繁体   English

Maven插件配置将参数设置为class

[英]Maven plugin configuration set parameter to class

I'm developing a maven plugin with a goal that has a parameter of a class. 我正在开发一个目标为具有类参数的maven插件。

I want to configure this goal to use a special class. 我想将此目标配置为使用特殊类。

This is my Mojo of the maven plugin: 这是我的Maven插件的Mojo:

/**
 * The used parser.
 * 
 * @parameter expression="${parser}"
 */
private EndpointParser parser;

public void execute() throws MojoExecutionException {

This is my pom.xml of the project using the plugin: 这是我使用插件的项目的pom.xml:

...
<plugins>
        <plugin>
            <groupId>foo</groupId>
            <artifactId>bar</artifactId>
            <configuration>
                <parser>com.foo.bar.MyEndpointParser</parser>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <phase>generate-sources</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>
...

How do I get it working. 我如何使其工作。

If MyEndPointParser is not part of your plugin but another project (which is not isself a dependency of your plugin) you have to declare it as dependency not of your project but of your plugin eg 如果MyEndPointParser不是插件的一部分,而是另一个项目(它本身不是插件的依赖项),则必须将其声明为不是项目的依赖项,而是插件的依赖项,例如

<plugins>
    <plugin>
        <groupId>foo</groupId>
        <artifactId>bar</artifactId>
        <configuration>
            <parser>com.foo.bar.MyEndpointParser</parser>
        </configuration>

        <dependencies>
            <dependency>
                <groupId>foo</groupId>
                <artifactId>contains-my-endpoint-parser</artifactId>
            </dependency>
        </dependencies>

        <executions>
            <execution>
                <goals>
                    <goal>generate</goal>
                </goals>
                <phase>generate-sources</phase>
            </execution>
        </executions>
    </plugin>
</plugins>

I think this should work: 我认为这应该工作:

<configuration>
  <parser implementation="com.foo.bar.MyEndpointParser"/>
</configuration>

However, it's probably easier if you configure MyEndpointParser as a Component . 但是,如果将MyEndpointParser配置为Component ,可能会更容易。 I can't find any up2date documentation for it. 我找不到任何up2date文档。 You could have a look at the sources of the maven-compiler-plugin. 您可以看看maven-compiler-plugin的来源。 There you have a parameter for the compilerId to switch between implementations. 那里有一个参数供compilerId在实现之间切换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM