7

我有一个 maven-multi 项目,当我从中创建一个新的 eclipse 项目时(通过 M2E 1.0 “Checkout Maven Project from SCM”),我希望自动为该项目配置 eclipse checkstyle 插件。

所以我添加了maven-eclipse-pluginin parent pom's <pluginManagement>section 并将其配置为生成.checkstyle文件以及附加项目性质CheckstyleNature。在模块 poms 中,我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>

模块 pom - 插件部分:

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-eclipse-plugin</artifactId>
</plugin>
4

3 回答 3

5

可以通过 pom.xml 配置 m2eclipse 吗?

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

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

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

于 2011-12-19T20:52:57.643 回答
4

maven eclipse 插件与 eclipse 的 m2e 插件不同,我假设您正在尝试使用它。基本上你不应该同时使用两者。

您可以从命令行使用 mvn eclipse:eclipse 生成项目文件,然后您可以将项目导入 eclipse。M2e 的工作方式非常不同,当您将项目作为 maven 插件导入时,它会使用 pom 文件。可能您想要的是配置 checkstyle 插件,并希望 eclipse 会选择这些设置。findbugs 和其他 maven 插件也是如此。

但是,我实际上更喜欢使用 mvn eclipse:eclipse 并且实际上并没有按预期验证上述工作。M2e 对我来说太浪费时间了,而且似乎经常做错事。我特别讨厌它习惯于在与 maven 进行命令行交互后基本上重建所有内容。但是很多人似乎喜欢m2e。

于 2011-12-02T17:57:24.823 回答
1

必须安装“Checkstyle m2e”连接器

将配置从 maven-checkstyle-plugin 应用到 eclipse checkstyle 插件

在 window\preferences\Maven\Discover\Open Catalog 下

当然,必须更改 pom,以便配置检查样式插件,而不是 eclipse 插件。

不幸的是,它对我不起作用!(我不会删除答案,因为它可能对其他人有用。)

于 2011-12-02T18:27:39.740 回答