jib icon indicating copy to clipboard operation
jib copied to clipboard

IllegalArgumentException from ASM

Open coollog opened this issue 6 years ago • 11 comments

Experiencing this issue when trying to Jib up the Groovy project at https://github.com/coollog/skaffold-code.one/tree/master/frontend-service

* What went wrong:
Execution failed for task ':jib'.
> java.lang.IllegalArgumentException (no error message)

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
...
Caused by: java.lang.IllegalArgumentException
        at org.objectweb.asm.ClassVisitor.<init>(ClassVisitor.java:79)
        at org.objectweb.asm.ClassVisitor.<init>(ClassVisitor.java:64)
        at com.google.cloud.tools.jib.frontend.MainClassFinder$MainClassVisitor.<init>(MainClassFinder.java:123)
        at com.google.cloud.tools.jib.frontend.MainClassFinder$MainClassVisitor.<init>(MainClassFinder.java:111)
        at com.google.cloud.tools.jib.frontend.MainClassFinder.findMainClass(MainClassFinder.java:190)
        at com.google.cloud.tools.jib.frontend.MainClassFinder.find(MainClassFinder.java:161)
        at com.google.cloud.tools.jib.plugins.common.MainClassResolver.findMainClassInClassFiles(MainClassResolver.java:129)
        at com.google.cloud.tools.jib.plugins.common.MainClassResolver.resolveMainClass(MainClassResolver.java:61)
        at com.google.cloud.tools.jib.plugins.common.PluginConfigurationProcessor.computeEntrypoint(PluginConfigurationProcessor.java:278)
        at com.google.cloud.tools.jib.plugins.common.PluginConfigurationProcessor.processCommonConfiguration(PluginConfigurationProcessor.java:208)
        at com.google.cloud.tools.jib.plugins.common.PluginConfigurationProcessor.processCommonConfigurationForRegistryImage(PluginConfigurationProcessor.java:155)
        at com.google.cloud.tools.jib.gradle.BuildImageTask.buildImage(BuildImageTask.java:104)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at 
...

coollog avatar Jan 30 '19 15:01 coollog

This ended up being a problem with the com.github.johnrengelman.shadow plugin using an older version of asm. Since this doesn't seem to be jib's fault, I'm going to close this.

However, we did end up finding a new issue, which I filed here #1456

TadCordle avatar Jan 30 '19 18:01 TadCordle

We may want to file an issue or PR at https://github.com/johnrengelman/shadow to upgrade their ASM dependency.

TadCordle avatar Jan 30 '19 18:01 TadCordle

@TadCordle sounds like a good idea.

loosebazooka avatar Feb 06 '19 18:02 loosebazooka

I could solve this problem by adding the main class to the Manifest

Example:

jar {
    manifest {
        attributes 'Main-Class': 'com.package.HelloWorld'
    }
}

javiersigler avatar Sep 29 '19 08:09 javiersigler

Another similar solution would be this:

jib {
    container {
        mainClass = 'com.package.HelloWorld'
    }
}

This way, you can add further parameters. See https://github.com/GoogleContainerTools/jib/blob/master/jib-gradle-plugin/README.md#example

samuel-phan avatar Jan 29 '21 15:01 samuel-phan

@samuel-phan ~~if you hit IllegalArgumentException, it's an issue in our code to automatically infer a main class. Setting a main class explicitly can side-step the issue, but it's still an issue. If you could share a simple reproducible case with us, we should be able to easily fix it.~~ UPDATE: I missed the old comments above. The issue seems to be due to an old ASM dependency pulled in.

chanseokoh avatar Jan 29 '21 16:01 chanseokoh

Hey @chanseokoh , I would gladly help but I just inherited a Java project and I'm trying to build the Java container faster and in better way. I don't know much about Java itself. Sorry that I can't help more. And on the side note, Jib is amazing 👍 🥇 😃

samuel-phan avatar Jan 29 '21 16:01 samuel-phan

I ran into this as well. Gradle's shadow JAR plugin is used by a lot of projects, and after upgrading to the latest version of shadow JAR I still got this error. It would be really nice if Jib helped developers here, for example by mentioning this pitfall in some documentation. Or maybe the plugin could check the version of ASM that it runs with, and print an informative error message before the IllegalArgumentException that ASM produces.

martijndwars avatar Mar 04 '21 16:03 martijndwars

@MartijnDwars thanks for the feedback. Normally Gradle should pick up the most latest versions for dependencies when there are conflicts. However, we learned that it is a general and recurring issue in Gradle where an old version of a dependency is loaded in a multi-module Gradle project which leads to a frequent 'Method Not Found" or "Class Not Found" exception. The good news is that, with proper project configuration, this can be fixed, so in some sense, this is a Gradle configuration issue in your project. Check out this FAQ to learn more.

Or maybe the plugin could check the version of ASM that it runs with, and print an informative error message before the IllegalArgumentException that ASM produces.

Since this is a general Gradle configuration issue that can happen with any transitive dependencies of Jib (ASM happens to be the one here) and whose error can manifest in any unpredictable behavior (e.g., Method Not Found, or some behavior that works slightly differently, etc.), generally it doesn't make much sense to increase Jib's code complexity by adding a special handling for this particular IllegalArgummentException only for ASM. This is more or less out of the scope of Jib. However, if this particular error is frequent and consistent enough and many users keep running into it, it may not be unreasonable to try to catch this situation and return a helpful message. But for now, I think adding an FAQ entry is good enough. I'll reopen this issue for tracking. Doc contributions are welcome.

chanseokoh avatar Mar 04 '21 17:03 chanseokoh

Agreed, thanks for the quick reply.

martijndwars avatar Mar 04 '21 17:03 martijndwars