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

Issue using @GenerateTypeAdapter with maven #258

Closed
mseele opened this issue Mar 31, 2021 · 2 comments
Closed

Issue using @GenerateTypeAdapter with maven #258

mseele opened this issue Mar 31, 2021 · 2 comments

Comments

@mseele
Copy link
Contributor

mseele commented Mar 31, 2021

I experienced an issue with the maven configuration of auto-value-gson-extension using @GenerateTypeAdapter.
Please see my demo Repository here: https://github.com/mseele/auto-value-gson-test

When i run mvn clean compile with the current setup, no Test_GsonTypeAdapter is created.

I deep dive into the issue by debugging via mvnDebug clean compile and found out that com.google.auto.value.processor.AutoValueProcessor.init(ProcessingEnvironment) throws the following error:

[AutoValueExtensionsException] An exception occurred while looking for AutoValue extensions. No extensions will function.java.lang.NoClassDefFoundError: com.squareup.javapoet.TypeName
	at java.base/java.lang.J9VMInternals.prepareClassImpl(Native Method)
	at java.base/java.lang.J9VMInternals.prepare(J9VMInternals.java:341)
	at java.base/java.lang.Class.getConstructor(Class.java:669)
	at com.google.auto.value.processor.SimpleServiceLoader.load(SimpleServiceLoader.java:73)
	at com.google.auto.value.processor.SimpleServiceLoader.load(SimpleServiceLoader.java:49)
	at com.google.auto.value.processor.AutoValueProcessor.extensionsFromLoader(AutoValueProcessor.java:105)
	at com.google.auto.value.processor.AutoValueProcessor.init(AutoValueProcessor.java:115)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.<init>(JavacProcessingEnvironment.java:686)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors$ProcessorStateIterator.next(JavacProcessingEnvironment.java:786)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:881)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1222)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1335)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1258)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:936)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
	at com.sun.tools.javac.api.JavacTaskImpl$$Lambda$136/0x0000000000000000.call(Unknown Source)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:147)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
	at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:126)
	at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:174)
	at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1134)
	at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:187)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
Caused by: java.lang.ClassNotFoundException: com.squareup.javapoet.TypeName
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:605)
	at java.base/java.lang.ClassLoader.loadClassHelper(ClassLoader.java:1185)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:1100)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:1083)
	... 45 more

(but unfortunately is not output in the console)

Adding

<path>
    <groupId>com.squareup</groupId>
    <artifactId>javapoet</artifactId>
    <version>1.13.0</version>
</path>

to the <annotationProcessorPaths> triggers the next exception (now visible on the console):

Fatal error compiling: java.lang.NoClassDefFoundError: com.ryanharter.auto.value.gson.GenerateTypeAdapter

After adding

<path>
    <groupId>com.ryanharter.auto.value</groupId>
    <artifactId>auto-value-gson-runtime</artifactId>
    <version>${auto-value-gson.version}</version>
</path>

everything works.

Please see https://github.com/mseele/auto-value-gson-test/blob/master/pom.xml. The current version triggers the error. I've commented out the two items that need to be there to make it work.

@ZacSweers
Copy link
Collaborator

Not very familiar with using maven, seems your build is not resolving dependencies. This works fine in basically every Gradle project so not sure there's anything we can do here. Seems you'll need to troubleshoot your build issue

@mseele
Copy link
Contributor Author

mseele commented May 11, 2021

Just for documentation reasons:
I got time to look into this a little deeper. Seems like i ran into this maven bug:
https://issues.apache.org/jira/browse/MCOMPILER-272

Only the transitive dependencies of the first entry are resolved so far. Moving path auto-value-gson-extension up will resolve the issue.

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

No branches or pull requests

2 participants