简体   繁体   English

groovy-eclipse-compiler 编译但 javac 编译失败

[英]groovy-eclipse-compiler compiles but javac compilation fails

My project builds successfully with groovy-eclipse-compiler, but fails without groovy-eclipse-compiler (using just javac).我的项目使用 groovy-eclipse-compiler 成功构建,但在没有 groovy-eclipse-compiler 的情况下失败(仅使用 javac)。 The build fails with an error message as given below (reported in a test class, while mocking an invocation)构建失败并显示如下错误消息(在测试类中报告,同时模拟调用)

java: reference to getFileResource is ambiguous

In order to debug the issue, I created a project with minimal files (given below).为了调试问题,我创建了一个包含最少文件的项目(如下所示)。 Though in project we have groovy source also, but I have not included them here to keep the code minimal.虽然在项目中我们也有 groovy 源代码,但我没有将它们包含在这里以保持代码最少。 The code is also pushed to git and is available at https://github.com/kaushalkumar/project-debug代码也被推送到 git 并且可以在https://github.com/kaushalkumar/project-debug 获得

My Doubt : The reported issue looks to be legitimate and I feel that groovy-eclipse-compiler must also fail, but it seems that the error is ignored.我的怀疑:报告的问题看起来是合法的,我觉得 groovy-eclipse-compiler 也必须失败,但似乎忽略了错误。 I am trying to understand what make groovy compiler to ignore it.我试图了解是什么让 groovy 编译器忽略它。 Is it an issue in groovy compiler?这是 groovy 编译器的问题吗?

src/main/java/pkg1/IStrategy.java package pkg1; src/main/java/pkg1/IStrategy.java包 pkg1;

import java.util.Map;

public interface IStrategy {
    Map<String, Object> getEnvMap();
}

src/main/java/pkg1/SharedResourceHelper.java package pkg1; src/main/java/pkg1/SharedResourceHelper.java包 pkg1;

import java.io.File;
import java.io.IOException;
import java.util.Map;

public class SharedResourceHelper {
    public static File getFileResource(final String resourceName, final IStrategy strategy) throws IOException {
      return getFileResource(resourceName, strategy.getEnvMap());
    }
    public static File getFileResource(final String resourceName, final Map<String, Object> envConfig) throws IOException {
      return null;
    }
}

src/test/java/pkg1/StrategyTest.java package pkg1; src/test/java/pkg1/StrategyTest.java包 pkg1;

import pkg1.SharedResourceHelper;
import org.easymock.EasyMock;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.junit.Test;
import org.powermock.modules.junit4.PowerMockRunner;
import org.junit.runner.RunWith;
import java.io.File;

@PrepareForTest({SharedResourceHelper.class})
@RunWith(PowerMockRunner.class)
public class StrategyTest {
    @Test
    @PrepareForTest({SharedResourceHelper.class})
    public void testGetFileResource() throws Exception {
      PowerMock.mockStatic(SharedResourceHelper.class);
      EasyMock.expect(SharedResourceHelper.getFileResource(EasyMock.anyString(), EasyMock.anyObject())).andReturn(File.createTempFile("tmp", "s"));
//      EasyMock.expect(SharedResourceHelper.getFileResource("test", null)).andReturn(File.createTempFile("tmp", "s"));
      
    }
}

/pom.xml /pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>project.debug</groupId>
  <artifactId>project</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <dependencies>
    <dependency>
      <groupId>org.powermock</groupId>
      <artifactId>powermock-api-easymock</artifactId>
      <version>2.0.7</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.powermock</groupId>
      <artifactId>powermock-module-junit4</artifactId>
      <version>2.0.7</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <compilerId>groovy-eclipse-compiler</compilerId>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-compiler</artifactId>
            <version>2.9.2-01</version>
          </dependency>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-batch</artifactId>
            <version>2.4.3-01</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
</project>
  • Java version - 1.8.0_231 Java 版本 - 1.8.0_231
  • Maven - 3.6.2 Maven - 3.6.2
  • OS - Mac 10.15.6操作系统 - Mac 10.15.6
  • groovy-eclipse-compiler - 2.9.2-01 groovy-eclipse-compiler - 2.9.2-01
  • groovy-eclipse-batch - 2.4.3-01 groovy-eclipse-batch - 2.4.3-01

You reference "SharedResourceHelper.getFileResource(EasyMock.anyString(), EasyMock.anyObject())" is indeed ambiguous.您引用“SharedResourceHelper.getFileResource(EasyMock.anyString(), EasyMock.anyObject())”确实含糊不清。 If you add a typecast before "EasyMock.anyObject()" you could disambiguate.如果您在“EasyMock.anyObject()”之前添加类型转换,您可以消除歧义。 And EasyMock probably provides an "any" method that you can pass a type into as well. EasyMock 可能提供了一个“any”方法,您也可以将类型传递给它。

groovy-eclipse-compiler is based upon ecj (eclipse compiler for java) and not javac, so there are bound to be differences. groovy-eclipse-compiler 基于 ecj(用于 java 的 eclipse 编译器)而不是 javac,因此肯定会有差异。 It may also be that ecj has a different default error/warning level for this particular case.对于这种特殊情况,ecj 也可能具有不同的默认错误/警告级别。 If you feel this should be an error, you can file a JDT bug at bugs.eclipse.org.如果您觉得这应该是一个错误,您可以在 bugs.eclipse.org 上提交 JDT 错误。

eric-milles gave some direction to further explore this. eric-milles给出了一些进一步探索这个的方向。 His input is available at https://github.com/groovy/groovy-eclipse/issues/1157 .他的意见可在https://github.com/groovy/groovy-eclipse/issues/1157 获得

Based on his comment, we explored the history of https://github.com/groovy/groovy-eclipse/blob/master/extras/groovy-eclipse-batch-builder/build.properties and found that the compilation issue was between 2.4.12-01 (compilation works) and 2.4.12-02 (compilation breaks- as expected), which was part of release 2.9.2.根据他的评论,我们探索了https://github.com/groovy/groovy-eclipse/blob/master/extras/groovy-eclipse-batch-builder/build.properties的历史,发现编译问题在 2.4 之间.12-01(编译工作)和 2.4.12-02(编译中断 - 正如预期的那样),这是 2.9.2 版的一部分。

The change happened on Aug 10, 2017 (13c1c2a#diff-c8c111c3afb6080ae6b32148caaf6a0a), with comment as "Remove codehaus references".更改发生在 2017 年 8 月 10 日 (13c1c2a#diff-c8c111c3afb6080ae6b32148caaf6a0a),注释为“删除 codehaus 引用”。 The jdt.patch.target was targeted for e44 which is Luna. jdt.patch.target 的目标是 e44,也就是 Luna。 This was same for both the files.这对于两个文件都是一样的。

I invested some time in exploring https://github.com/eclipse/eclipse.jdt.core , to figure out how compiler behaviour could have altered, but could not get much.我花了一些时间来探索https://github.com/eclipse/eclipse.jdt.core ,以找出编译器行为如何改变,但没有得到太多。 Though I am not very sure, but I feel that change in groovy-eclipse-batch (between 2.4.12-01 and 2.4.12-02) might be the cause of this.虽然我不太确定,但我觉得 groovy-eclipse-batch(在 2.4.12-01 和 2.4.12-02 之间)的变化可能是造成这种情况的原因。

Having invested this much time, I feel that it is not worth to further debug on this to figure out the root cause as the issue is already fixed in next version(s) [2.4.12-02 and beyond].投入了这么多时间,我觉得不值得进一步调试以找出根本原因,因为该问题已在下一个版本 [2.4.12-02 及更高版本] 中解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用Maven和groovy-eclipse-compiler编译Groovy - Compiling Groovy with Maven and groovy-eclipse-compiler 使用Javac编译失败,使用eclipse-compiler可以正常工作 - Compilation with javac fails, with eclipse-compiler it works groovy-eclipse-compiler不显示编译器错误 - groovy-eclipse-compiler does not show compiler error 使用带有groovy-eclipse-compiler的querydsl-maven-plugin生成QueryDsl类 - generating QueryDsl classes using querydsl-maven-plugin with groovy-eclipse-compiler 项目如何在eclipse中编译,但javac会抛出编译器错误? - How is it possible that a project compiles in eclipse, but javac throws compiler errors? eclipse编译器编译javac不会编写的代码 - 代码看起来是合法的 - eclipse compiler compiles code that javac will not - code looks to be legal Java泛型代码使用javac编译,Eclipse Helios失败 - Java generics code compiles with javac, fails with Eclipse Helios 使用Eclipse时,Maven编译失败并显示“找不到符号”,它编译 - Maven compilation fails with “cannot find symbol” while with Eclipse, it compiles 在Eclipse中编译但不在命令行中使用Javac编译:StackOverFlow - Compiles in Eclipse but not with Javac from command line: StackOverFlow Java CRTP和通配符:代码在Eclipse中编译,但不是`javac` - Java CRTP and Wildcards: Code compiles in Eclipse but not `javac`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM