Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalArgumentException from ASM #1455

Open
coollog opened this issue Jan 30, 2019 · 11 comments · May be fixed by #4252
Open

IllegalArgumentException from ASM #1455

coollog opened this issue Jan 30, 2019 · 11 comments · May be fixed by #4252

Comments

@coollog
Copy link
Contributor

coollog commented Jan 30, 2019

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 
...
@TadCordle
Copy link
Contributor

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
Copy link
Contributor

TadCordle commented Jan 30, 2019

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

@loosebazooka
Copy link
Member

@TadCordle sounds like a good idea.

@javiersigler
Copy link

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

Example:

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

@samuel-phan
Copy link

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

@chanseokoh
Copy link
Member

chanseokoh commented Jan 29, 2021

@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.

@samuel-phan
Copy link

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 👍 🥇 😃

@martijndwars
Copy link

martijndwars commented Mar 4, 2021

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.

@chanseokoh chanseokoh changed the title IllegalArgumentException on a Groovy project IllegalArgumentException from ASM Mar 4, 2021
@chanseokoh
Copy link
Member

chanseokoh commented Mar 4, 2021

@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.

@martijndwars
Copy link

Agreed, thanks for the quick reply.

@markusheiden markusheiden linked a pull request Oct 5, 2024 that will close this issue
@markusheiden
Copy link
Contributor

Another workaround is

buildscript {
    dependencies {
        classpath('org.ow2.asm:asm:9.7')
    }
}

in settings.gradle to bump the asm version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.