我正在尝试使用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>
答案 0 :(得分:14)
问题在于构建帮助程序插件通常太旧而无法与最新的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>