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

Unable to load class 'com.palantir.javapoet.AnnotationSpec'. #102

Open
kevinm416 opened this issue Oct 17, 2024 · 4 comments
Open

Unable to load class 'com.palantir.javapoet.AnnotationSpec'. #102

kevinm416 opened this issue Oct 17, 2024 · 4 comments

Comments

@kevinm416
Copy link

kevinm416 commented Oct 17, 2024

What happened?

I switched from square.javapoet 1.13.0 to palantir.javapoet 0.5.0 according to the migration instructions.

dependencies {
  compileOnly 'com.squareup:javapoet:1.13.0'
  compileOnly group: 'com.google.auto.service', name: 'auto-service', version: '1.1.1'
  annotationProcessor group: 'com.google.auto.service', name: 'auto-service', version: '1.1.1'
}

Became:

dependencies {
  compileOnly 'com.palantir.javapoet:javapoet:0.5.0'
  compileOnly group: 'com.google.auto.service', name: 'auto-service', version: '1.1.1'
  annotationProcessor group: 'com.google.auto.service', name: 'auto-service', version: '1.1.1'
}

After fixing the fields -> getters as mentioned in the migration instructions, I tried to build the project with Palantir's version of the library, and I got the error:

Unable to load class 'com.palantir.javapoet.AnnotationSpec'.
This is an unexpected error. Please file a bug containing the idea.log file.

This is the contents of idea.log:


2024-10-16 21:44:35,694 [906222664]   INFO - #o.j.p.g.GradleManager - Instructing gradle to use java from /Users/kevin/Library/Java/JavaVirtualMachines/corretto-21.0.1/Contents/Home
2024-10-16 21:44:35,695 [906222665]   INFO - #o.j.p.g.GradleManager - Instructing gradle to use java from /Users/kevin/Library/Java/JavaVirtualMachines/corretto-21.0.1/Contents/Home
2024-10-16 21:44:35,699 [906222669]   INFO - #o.j.p.g.s.e.GradleExecutionHelper - Passing command-line to Gradle Tooling API: [projects] :buildSrc:classes :buildSrc:testClasses --init-script /private/var/folders/7j/8y7kchxj02b2xs5qfdqsk8t00000gn/T/ijMapper1.gradle --init-script /private/var/folders/7j/8y7kchxj02b2xs5qfdqsk8t00000gn/T/ijresolvers1.gradle -Didea.active=true -Didea.version=2024.2.2 -Didea.vendor.name=JetBrains
2024-10-16 21:44:39,531 [906226501]   INFO - #c.i.w.i.i.j.s.JpsGlobalModelSynchronizerImpl - Saving global entities com.intellij.platform.workspace.jps.entities.SdkEntity to files
2024-10-16 21:44:39,532 [906226502]   INFO - #c.i.w.i.i.j.s.JpsGlobalModelSynchronizerImpl - Saving global entities com.intellij.platform.workspace.jps.entities.LibraryEntity to files

And building directly with gradle:

$ gw spotA build

> Configure project :

> Task :project-processor:compileJava FAILED
/Users/kevin/.../RecordBuilderAnnotationProcessor.java:4: error: package com.palantir.javapoet does not exist
import com.palantir.javapoet.AnnotationSpec;
                            ^
/Users/kevin/.../RecordBuilderAnnotationProcessor.java:5: error: package com.palantir.javapoet does not exist
import com.palantir.javapoet.JavaFile;

I can work around this by using the implementation configuration, but that packages the jar into the application. Since this library is meant to be used at compile time, I just want to use it to generate code at compile time and not have it on the classpath at runtime. I was able to accomplish that with the compileOnly configuration of com.squareup:javapoet.

What did you want to happen?

To get the exact same output as I was getting from square.javapoet.

@skku-daniilkim
Copy link
Contributor

This does not seem like an issue with "javapoet" imo. Have you tried reimporting the project and fully cleaning the build directory?

@kevinm416
Copy link
Author

I get the same behavior using gradle directly, so It's not an intellij issue.

@skku-daniilkim
Copy link
Contributor

Could you try version 0.3.0. Perhaps something went wrong after adding the JPMS compatibility.

@kevinm416
Copy link
Author

It looks like the same issue as in 0.3.0, but the error is slightly different:

dependencies {
  compileOnly 'com.palantir.javapoet:javapoet:0.3.0'
  compileOnly group: 'com.google.auto.service', name: 'auto-service', version: '1.1.1'
  annotationProcessor group: 'com.google.auto.service', name: 'auto-service', version: '1.1.1'
}
$ ./gradlew build

> Configure project :
Version: 0.7.0-812b668

> Task :model:compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':model:compileJava'.
> com/palantir/javapoet/AnnotationSpec

Error from inside intellij is the same:

Unable to load class 'com.palantir.javapoet.AnnotationSpec'.
This is an unexpected error. Please file a bug containing the idea.log file.

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