首页 文章

使用maven Build Helper Maven插件

提问于
浏览
13

我正在尝试使用maven插件将maven java项目的源文件夹添加到Eclipse .

当尝试使用org.codehaus.mojo插件时,我收到以下错误

无法在项目应用程序框架上执行目标org.codehaus.mojo:build-helper-maven-plugin:1.7:add-source(default-cli):目标org.codehaus.mojo的参数'sources':build-helper -maven-plugin:1.7:add-source缺失或无效 - > [帮助1]

从阅读http://mojo.codehaus.org/build-helper-maven-plugin/usage.html上的文档来看,这应该是正确的吗?文件夹target / sources / mygeneratedfiles on存在 .

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
        <execution>
         <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>target/sources/mygeneratedfiles</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>

1 回答

  • 13

    问题是,由于“相对较新的”生命周期映射规则,构建帮助程序插件通常太旧而无法与最新的maven版本(与m2e eclipse插件结合使用)一起使用 .

    我通过为orgeclipse.m2e plugib的build-helper-maven-plugin添加lifecyclemapping配置解决了这个问题 . 见下文:

    <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.codehaus.mojo</groupId>
                                    <artifactId>build-helper-maven-plugin</artifactId>
                                    <versionRange>[1.0,)</versionRange>
                                    <goals>
                                        <goal>add-source</goal>
                                        <goal>add-test-source</goal>
                                        <goal>add-resource</goal>
                                        <goal>add-test-resource</goal>
                                        <goal>maven-version</goal>
                                        <goal>parse-version</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <execute>
                                        <runOnConfiguration>true</runOnConfiguration>
                                        <runOnIncremental>true</runOnIncremental>
                                    </execute>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
    

相关问题