如何在IntelliJ IDEA上增加100个错误的错误限制?

sor*_*rin 13 intellij-idea

我有一个IntelliJ IDEA的项目,但是当它遇到超过100个错误,我想以提高额度,以弄清楚我多少钱要"重构"古代码的编译停止.

Nic*_*ume 25

您看到的100错误限制本身并不是IntelliJ IDEA的限制,而是javac用于编译应用程序的编译器的默认值.IDEA使用后.默认的错误数,after是标准Sun/Oracle javac编译器的默认值,但可以通过将参数传递给编译器来修改; 最大警告数也可以,默认为100.

javac的在线文档(例如,'javac的Java SE版本7页- Java编程语言编译器' )给出了这些参数(在" 选项 " 部分的" 非标准选项 " 子标题下),如下所示:

-Xmaxerrs number
     Set the maximum number of errors to print.

-Xmaxwarns number
     Set the maximum number of warnings to print.

当使用javac在IntelliJ IDEA的,这些(和其他)编译器参数可以通过导航到的设置项目(例如,被添加F?ile > Set?tingsCtrl+ Alt+ S); 然后,在Project Settings标题下,展开该? Compiler部分,选择Java Compiler并在下面的文本框中输入所需的设置Additional command line parameters:.(例如,要增加123错误和456警告的限制,请进入-Xmaxerrs 123 -Xmaxwarns 456文本框.)

   来自http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html,检索2014-07-31,由WebCite®存档,网址为http://www.webcitation.org/ 6RTlsAI8T

   这个过程在版本13上由shelleybutterfly审查,版本12由Nicolas Guillaume审查,但对于其他版本,该过程可能非常相似,如果不相同的话.

  • 如果“其他命令行参数”文本框似乎没有生效。您可能需要检查“覆盖每个模块的编译器参数”部分中的字段,以确保您的模块不会被其他内容覆盖。 (2认同)

Tim*_*mmm 15

如果您正在使用Gradle(可能是因为您使用的是Android),请更改allprojects项目的位build.gradle(而不是模块1),如下所示:

allprojects {
    repositories {
        jcenter()
    }

    // Allow 400 errors.
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xmaxerrs" << "400"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)


cb4*_*cb4 5

2022 UPDATE

The question is old but still valid when wanting to use current IDE technology on legacy code. For a maven build in intellij, Nicolas Guillaume's answer will not work - those settings are rightly overridden by maven. However, this configuration will yield the same result:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.10.0</version>
    <configuration>
        <fork>true</fork>
        <compilerVersion>1.5</compilerVersion>
        <executable>C:\Java\jdk-1.5.0_22\bin\javac.exe</executable>
        <source>1.5</source>
        <target>1.5</target>
        <compilerArgs>
            <arg>-Xmaxerrs</arg>
            <arg>1000</arg>
            <arg>-Xmaxwarns</arg>
            <arg>2000</arg>
        </compilerArgs>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

Some sources (even on SO) state that the correct option for Java5 is -Xmaxerrors, which is incorrect as reported in this bug. And that option didn't exist in 1.4 and earlier versions.


Cra*_*der 3

注意:尽管可以按照本答案的建议更改为Eclipse编译器,但没有必要解决此特定问题.相反,您可以简单地在编译器设置中添加一个参数,以更改编译器显示的最大错误数javac(如Nicolas Guillaume 提出的问题替代答案中所述).

由于在现有项目中切换到不同的编译器或编译器版本时可能会出现微妙的问题,因此请确保在进行切换之前了解给定特定情况的后果,如下所述.

IntelliJ IDEA不强制执行此限制,它是特定于编译器的(在这种情况下,javac编译器具有100个错误的限制).

要解决此问题,您可以在Settings|中切换到另一个编译器 Compiler| Java Compiler.Eclipse编译器应该能够显示更多错误.

  • 您似乎是正确的,这是由于编译器造成的,但是 Nicolas 传递 -Xmaxerrors 参数的解决方案有效(不需要更改编译器,至少在我的情况下) (2认同)