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

标签 java eclipse maven checkstyle m2e

我有一个 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-qualitym2e-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/

相关文章:

java - HQL查询帮助(分组依据、排序依据)

java - 整个项目的语法突出显示已损坏

Spring boot 项目未解析依赖项 - 无法在 org.springframework.boot :spring-boot-starter-web:jar:2. 1.1.RELEASE 处收集依赖项

eclipse - 不同 Eclipse 工作区的不同 M2_HOME

Scala 中的 Java IO

java - @ManyToOne 错误 - JPA/Hibernate 分离实体传递到持久化

java - 使用 Envers 和 Hibernate Spatial 4 进行审计

java - 如何使用 Arrays.sort() 按字母顺序排列字符串的顺序?

安卓模拟器 : select AVD (Android Virtual Device) to run by default

eclipse - 安装ADT插件时出错 'Cannot complete the install '