如何为checkstyle定义抑制定义,它们同时适用于ant和eclipse

Mne*_*nth 8 ant continuous-integration build-process eclipse-plugin checkstyle

我在项目checkstyle中使用,我在checkstyle-configuration中定义了一个SuppressionFilter.我使用Apache ant通过持续集成进行自动构建.

我的问题来自以下情况:我不想将大量文件填充到基于项目的文件中,因此checkstyle.xml和suppressions.xml都位于名为conf的子目录中(用于构建的配置).现在Ant和Eclipse在查找suppressions.xml方面的工作方式不同.

在我声明了一个ant-task来查找checkstyle的基本配置的checkstyle.xml之后,Ant使用基于项目的basedir作为basedir来查找suppressions.xml.此checkstyle.xml现在包含以下内容:

<module name="SuppressionFilter">
    <property name="file" value="conf/suppressions.xml"/>
</module>
Run Code Online (Sandbox Code Playgroud)

这样ant-build就会找到suppressions.xml,因为构建的basedir是项目目录.

现在使用Eclipse 的checkstyle-plugin带来了一个问题.它从checkstyle.xml具有的路径(conf)开始查找suppressions.xml.对于Eclipse,声明必须看起来像这样,工作:

<module name="SuppressionFilter">
    <property name="file" value="suppressions.xml"/>
</module>
Run Code Online (Sandbox Code Playgroud)

编辑:即使这不起作用,Eclipse似乎总是需要一个绝对的路径.

我想知道一种方法,Eclipse和Ant都可以使用相同的checkstyle配置.有人知道这个问题的解决方案吗?绝对路径不是解决方案,因为每个开发人员和CI服务器都有不同的项目目录路径.

sli*_*eed 10

这个问题很老了,但我找到了一个更好的方法来使用Checkstyle Advanced属性:

对于Eclipse Checkstyle插件,该${samedir}属性将扩展到配置文件所在的目录:

在您的情况下,您的模块配置如下所示:

<module name="SuppressionFilter">
    <property name="file" value="${samedir}/conf/suppressions.xml" />
</module>
Run Code Online (Sandbox Code Playgroud)

Ant目标也会设置samedir属性:

<checkstyle config="${checkstyle.tool.dir}/checks.xml" failOnViolation="false">
    <fileset dir="${src.dir}" includes="**/*.java" />
    <property key="samedir" value="${checkstyle.tool.dir}/conf" />
</checkstyle>
Run Code Online (Sandbox Code Playgroud)


Sim*_*hke 7

使用Checkstyle的属性扩展功能.在你checkstyle.xml声明你SupressionFilter的:

<module name="SuppressionFilter">
    <property name="file" value="${checkstyle.suppressions.file}" default="suppressions.xml"/>
</module>
Run Code Online (Sandbox Code Playgroud)

然后在Ant构建脚本中修改Checkstyle任务以包含嵌套属性:

<checkstyle config="conf/checkstyle.xml">
    <fileset dir="src" includes="**/*.java"/>
    <property key="checkstyle.suppressions.file" value="conf/suppressions.xml"/>
</checkstyle>
Run Code Online (Sandbox Code Playgroud)