如何在Eclipse中为自动配置maven项目中的Checkstyle

Ral*_*lph 7 java eclipse checkstyle maven m2e

我有一个maven-multi项目,当我从它创建一个新的eclipse项目时(来自SCM的M2E 1.0"Checkout Maven项目")我希望自动为该项目配置eclipse checkstyle插件.

所以我添加了maven-eclipse-plugin父pom的 <pluginManagement>部分并将其配置为生成.checkstyle文件以及其他项目性质CheckstyleNature.在模块中我添加maven-eclipse-plugin了构建部分中的名称.但是当我检查项目没有发生任何事情时,文件不会生成,并且不会添加性质.

所以我认为我做的事情完全错了,但它是如何做得对的呢?


父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>
Run Code Online (Sandbox Code Playgroud)

模块pom - 插件部分:

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-eclipse-plugin</artifactId>
</plugin>
Run Code Online (Sandbox Code Playgroud)

Mar*_*ann 5

我可以通过pom.xml配置m2eclipse中有关于此主题的详细解答吗?:

Eclipse Checkstyle插件的完全自动配置只能通过ProjectConfigurator实现,例如m2e-code-qualitym2e-extensions.

对于版本1.0的m2e,您可以在Preferences-> Maven-> Discovery - >"Open Catalog"下通过m2e市场安装它们.有关详细信息,请参阅将m2e-code-quality集成到m2e市场错误跟踪.

即使对于FindBugs和Sonar,也有基于AntRun和XMLTask的解决方案.结帐后只需手动触发一次.