我有一个 maven-multi 项目,当我从它创建一个新的 eclipse 项目时(通过 M2E 1.0“从 SCM checkout Maven 项目”)我希望自动为该项目配置 eclipse checkstyle 插件。
所以我添加了 maven-eclipse-plugin
在父 pom 中 <pluginManagement>
部分并将其配置为生成 .checkstyle
文件以及附加项目性质CheckstyleNature
.在模块 poms 中,我添加了 maven-eclipse-plugin
的名称。在构建部分。但是当我 checkout 项目时没有任何反应,没有生成文件并且没有添加性质。
所以我认为我做的事情是完全错误的,但是如何做才是正确的呢?
父pom——插件管理部分:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<wtpversion>2.0</wtpversion>
<additionalBuildcommands>
<buildCommand>
<name>org.eclipse.ajdt.core.ajbuilder</name>
<arguments>
<aspectPath>org.springframework.aspects</aspectPath>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
</buildCommand>
</additionalBuildcommands>
<additionalProjectnatures>
<projectnature>org.eclipse.ajdt.ui.ajnature</projectnature>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
<projectnature>com.atlassw.tools.eclipse.checkstyle.CheckstyleNature</projectnature>
</additionalProjectnatures>
<additionalConfig>
<file>
<name>.checkstyle</name>
<content>
<![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
<fileset name="all" enabled="true" check-config-name="My Checkstyle rules" local="false">
<file-match-pattern match-pattern="." include-pattern="true"/>
</fileset>
<filter name="FilesFromPackage" enabled="true">
<filter-data value="target" />
<filter-data value="src/main/resources"/>
<filter-data value="src/test/java"/>
<filter-data value="src/test/resources"/>
<filter-data value="src/main/webapp" />
</filter>
</fileset-config>
]]>
</content>
</file>
</additionalConfig>
</configuration>
</plugin>
模块 pom - 插件部分:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
</plugin>
最佳答案
在Can I Configure m2eclipse through pom.xml?中有这个主题的详细答案。 :
Eclipse Checkstyle 插件的完全自动配置只能通过 ProjectConfigurator 来实现,例如m2e-code-quality或 m2e-extensions .
对于 1.0 版的 m2e,您可以通过 m2e 市场在 Preferences->Maven->Discovery->"Open Catalog"下安装它们。有关详细信息,请参阅 bug tracking for integration of m2e-code-quality into the m2e marketplace .
还有一个基于 AntRun 和 XMLTask 的解决方案,甚至适用于 FindBugs 和 Sonar。它只需要在结帐后手动触发一次。
关于java - 如何在 Eclipse 中自动为 maven 项目配置 Checkstyle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8360131/