google / closure-compiler

A JavaScript checker and optimizer.
https://developers.google.com/closure/compiler/
Apache License 2.0
7.41k stars 1.15k forks source link

Unable to Build on MacOS - AutoValue exceptions #2465

Closed ChadKillingsworth closed 7 years ago

ChadKillingsworth commented 7 years ago

At master I'm getting the following exceptions when trying to build:

/Users/chad/git/closure-compiler/src/com/google/javascript/refactoring/CodeReplacement.java:[29,16] error: @AutoValue processor threw an exception: java.lang.RuntimeException: exception during invocation of getAnnotationMirrors

    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure

I'm assuming since travis is passing, this is specific to MacOS. Still trying to figure out what's wrong and how to fix it.

ChadKillingsworth commented 7 years ago

This was definitely caused by 799ea5fe0b63f7354e9dc3428ed01ce99862f83c

eamonnmcmanus commented 7 years ago

Are there any compiler error messages before this exception? There should be one that contains the stack trace of the original exception, which should make it easier to diagnose what is going on.

Is there anything unusual about the JDK environment being used? The exception in question happens in code that tries to invoke a method that was introduced in Java 8, via reflection so that the code can work on Java 7. We've actually deleted that in the latest snapshot, since we no longer support running on pre-Java-8. Do you have a way of trying this with AutoValue 1.5-SNAPSHOT?

ChadKillingsworth commented 7 years ago

There is no other exception. All the other warnings were already present. The stack trace was produced by using the -e -X flags with Maven. The normal build just gives this single error message:

/Users/chad/git/closure-compiler/src/com/google/javascript/refactoring/CodeReplacement.java:[29,16] error: @AutoValue processor threw an exception: java.lang.RuntimeException: exception during invocation of getAnnotationMirrors

I switched to using the 1.5-SNAPSHOT version but it still gave the error.

There is nothing unusual about my build environment. I'm using jdk1.8.0_60.

eamonnmcmanus commented 7 years ago

I tried cloning git@github.com:google/closure-compiler and executing mvn package in the closure-compiler/ directory. It worked fine. java -version reports 1.8.0_25 (I'll try again with a more recent version). mvn -version reports 3.2.3. Is there something else I should be trying?

Incidentally the Maven dependencies on AutoValue should have <scope>provided</scope>. AutoValue does its work at compile time and there is no need to include it in your output jars.

ETA: I also tried with Java 1.8.0_131 and Maven 3.5.0, and it still worked.

eamonnmcmanus commented 7 years ago

Also, it should not be possible to get the message java.lang.RuntimeException: exception during invocation of getAnnotationMirrors when running against AutoValue 1.5-SNAPSHOT. If you get an exception, it should be a different one.

ChadKillingsworth commented 7 years ago

I updated both the pom-gwt.xml and pom-main.xml to have version 1.5-SNAPSHOT and <scope>provided</scope>. I get exactly the same error.

I ran mvn -U install and watched as the 1.5-SNAPSHOT was downloaded. My ~/.m2/repository only contains the 1.5-SNAPSHOT - no other versions.

Is it possible one of the other Google dependencies has bundled an older version that's conflicting?

eamonnmcmanus commented 7 years ago

I guess the more fundamental question is why you are getting an exception and I am not. I'm using mvn package within the root of the source tree. Should I be doing something else?

Have other people run into the same problem?

ChadKillingsworth commented 7 years ago

Nobody else has reported the problem yet, but the commit only got pushed externally last Tuesday. The command you ran gives the error for me (I normally run mvn install though).

Is there anything I can do to get more info or figure out exactly what is causing this?

eamonnmcmanus commented 7 years ago

Do you have anything unusual in ~/.m2/settings.xml? Perhaps try running Maven with -s $MVN/conf/settings.xml, where $MVN is the Maven install directory, to get default settings?

Perhaps there is something in ~/.m2/repository that is causing strangeness? I tried editing ~/.m2/settings.xml to add this immediately after <settings>: <localRepository>/tmp/fakerepository</localRepository> to see whether I was succeeding because of something in my repository, but it worked fine.

It worked for me with old versions of Maven and Java and also with latest versions, so the difference probably isn't there. I'm running on MacOS Sierra (10.12.4).

ChadKillingsworth commented 7 years ago

Using the default settings file had no effect. I tried deleting my repository and re-downloading everything. This also had no effect.

I'm on Maven 3.3.3, with Oracle JDK 1.8.0_131-b11 (64 bit) and MacOS Sierra (10.12.4).

Is there anyway I can locally build and link Auto Value so I can potentially step through the code and figure out what is causing the exception?

nicks commented 7 years ago

although I was not able to reproduce this compiler error (I'm also on osx), one thing I've seen happen in the past on osx is that you end up with multiple java things on the PATH (e.g., a jre7 and a jdk8), which causes weird compile failures that might look like this.

ChadKillingsworth commented 7 years ago

@nicks Wins the prize - Thanks Nick.

For posterity, this occurred because:

$ /usr/libexec/java_home 
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home

$ java -version 
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

$ /usr/bin/javac -version
javac 1.7.0_71

To fix it, I had to remove the extensions:

$ rm -rf ~/Library/Java/Extensions

$ sudo rm -rf /Library/Java/Extensions
eamonnmcmanus commented 7 years ago

Thanks @nicks!

The mechanics of this failure are still a bit mysterious to me but at least we'll hopefully be able to recognize it if it happens again.