【问题标题】:Ant build on InteliiJ Community Edition no compiler errors shownAnt 在 IntelliJ 社区版上构建,未显示编译器错误
【发布时间】:2012-11-14 16:40:54
【问题描述】:

我有一个想要在 IntelliJ Community Edition 11.1.4 中构建的现有项目,该版本在 Ubuntu 12.04.1 LTS 上运行

在 Ant Build 窗口中,我通过单击窗口左上角的 + 按钮并导航到文件来添加项目的 build.xml。列出了与构建文件关联的 ant 任务,我单击绿色播放按钮运行 ant 构建,它按预期开始。

我希望看到编译器错误并让 IntelliJ CE 显示这些编译器错误,并允许我在“消息”窗口中双击错误后跳转到(有问题的)源。

相反,消息窗口显示以下错误,当我双击它时,它会将我带到build.xml 文件中的javac ant 任务。

build.xml:389: Compile failed; see the compiler error output for details.

这是一个很好的建议,我非常想遵循它,但我不能,因为编译器错误不会显示在 Messages 窗口的任何地方。 Next 和 Previous Message 不会导航到实际的编译器错误。

我想知道如何在运行 Ant 构建的 IntelliJ 中查看编译器错误消息。

我尝试将 -v 标志添加到 Ant 命令行:执行属性中的字段。这对行为没有影响。

然后我尝试从 Ant 1.8 降级到 Ant 1.7。这次我确实看到了行为的变化。构建根本没有运行,我在终端收到以下错误https://gist.github.com/4073149

javac ant 任务如下所示。

<target name="compile-only" depends="">
    <stopwatch name="Compilation"/>
<javac destdir="${build.classes.dir}" debug="on" deprecation="off" 
       classpathref="base.path" excludes="/filtering/**/**">
    <src path="${src.dir}"/>
    <src path="${build.autogen.dir}"/>
</javac>
<!-- Copy all resource files to the output dir -->
<copy todir="${build.classes.dir}">
    <fileset dir="${src.dir}">
        <include name="**/*.properties"/>
        <include name="**/*.gif"/>
        <include name="**/*.png"/>
        <include name="**/*.jpg"/>
        <include name="**/*.svg"/>
        <include name="**/*.jpeg"/>
        <exclude name="**/.svn"/>
    </fileset>
</copy>
<stopwatch name="Compilation" action="total"/>

【问题讨论】:

    标签: ant intellij-idea


    【解决方案1】:

    IDEA 只是打印 Ant 的输出。尝试使用消息面板左侧的相应按钮将输出从树视图切换到纯文本视图:

    如果输出包含错误,您应该可以在那里看到它们。

    此外,使用 IDEA 提供的增量编译 (Build | Make) 更快、更容易。

    【讨论】:

    • 从树视图切换到纯文本有助于了解正在发生的事情。再次感谢您的提示。很明显,从 bash 中运行 ant 与 IntelliJ 之间存在关键的环境/配置差异。这是一个复杂的构建。当我弄清楚它是否足够通用时,将发布最终答案。 (今天没有机会)IntelliJ 不太可能出现问题,而是可能是 ant 1.8 与 ant 1.7 的问题或 Idea 内部的环境配置错误。再次感谢,罗布
    • @RobKielty,你有没有找到解决方案?我有一个非常相似的问题,很好奇你做了什么来解决它。
    • @Joshc1107 老实说,我不记得了,我现在正离开我自己的电脑去挖掘档案。我会说发布你的问题。 CrazyCoder 可能会帮助您了解正在发生的事情,我回家后会亲自帮助您。
    【解决方案2】:

    当为 ant IntelliJ 使用普通(非树)输出时 file (line,col): error msg javac 错误的格式。 但是错误视图解析器只能理解file:line: error msg 格式。

    您可以在 antIntegration.jar 的 PlainTextView 类中对其进行调整 http://grepcode.com/file/repository.grepcode.com/java/ext/com.jetbrains/intellij-idea/10.0/com/intellij/lang/ant/config/execution/PlainTextView.java#98

    我只是将 addJavacMessage 方法更改为跟随并重新编译了该类 ```java

     public void addJavacMessage(AntMessage message, String url) {
        final VirtualFile file = message.getFile();
        if (message.getLine() > 0) {
          final StringBuilder builder = StringBuilderSpinAllocator.alloc();
          try {
    
            if (file != null) {
              ApplicationManager.getApplication().runReadAction(new Runnable() {
                public void run() {
                  String presentableUrl = file.getPresentableUrl();
                  builder.append(presentableUrl);
    //              builder.append(' ');
                }
              });
            }
            else if (url != null) {
              builder.append(url);
    //          builder.append(' ');
            }
    //        builder.append('(');
            builder.append(':');
            builder.append(message.getLine());
            builder.append(':');
            builder.append(' ');
    //        builder.append(message.getColumn());
    //        builder.append(")");
            print(builder.toString(), ProcessOutputTypes.STDOUT);
          }
          finally {
            StringBuilderSpinAllocator.dispose(builder);
          }
        }
        print(message.getText(), ProcessOutputTypes.STDOUT);
      }
    
      public void addException(AntMessage exception, boolean showFullTrace) {
        String text = exception.getText();
        showFullTrace = false;
        if (!showFullTrace) {
          int index = text.indexOf("\r\n");
          if (index != -1) {
            text = text.substring(0, index) + "\n";
          }
        }
        print(text, ProcessOutputTypes.STDOUT);
      }
    

    ```

    现在我在 ant 工具的“纯文本”输出模式下有了可点击的链接。 请注意,“树模式”正确显示行和列 - 我使用的是 IDEA 13 CE。

    如果有人针对此问题为 Intellij 创建拉取请求,那就太好了。

    【讨论】:

      【解决方案3】:

      Ant 在 IntelliJ 中的正确用法:

      javac includeantruntime="false" srcdir="${src.dir}" fork="yes" executable="D:/jdk1.7/bin/javac"
            destdir="${classes.dir}" includes="**/*.java" source="7" classpathref="library.classpath" ...
      

      最重要的:

      executable="D:/jdk1.7/bin/javac"
      

      【讨论】:

        猜你喜欢
        • 2016-05-29
        • 2018-02-12
        • 1970-01-01
        • 2014-12-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-11
        • 1970-01-01
        相关资源
        最近更新 更多