8000 Apt template resolution from IDEA · Issue #221 · jstachio/jstachio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Apt template resolution from IDEA #221

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

Closed
taypo opened this issue Aug 10, 2023 · 19 comments
Closed

Apt template resolution from IDEA #221

taypo opened this issue Aug 10, 2023 · 19 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation good first issue Good for newcomers integration intellij

Comments

@taypo
Copy link
taypo commented Aug 10, 2023

I was trying Dave Syer's template demo and got the following error while building inside IDEA.
This with version 1.3.0 of jstachio. 1.2.0 failed with a similar error with a different path in the log.

/Users/bahadir/dev/personal/java-template-demo/src/main/java/demo/DemoModel.java:6:8
java: java.io.IOException: Failed to find template resource: 'templates/index.mustache'. Tried the following locations: 'file:/Users/bahadir/dev/personal/java-template-demo/target/classes/templates/index.mustache', '/Users/bahadir/dev/src/main/resources/templates/index.mustache'

First path seems to be correct, though I'm not sure about the file: prefix. Second path is definitely missing 2 directories in the middle. If you delegate build to maven from IDEA, everything works.

Thanks

@agentgt
Copy link
Contributor
agentgt commented Aug 10, 2023

I have been meaning to boot up IDEA on this project to test (I do use it from time to time).

Ironically I have been using Eclipse and VSCode because there usually the more problematic ones.

The first one is CLASS_OUTPUT. You can ignore the URI portion of it.

The reason it does not resolve is because IDEA has not copied over the resources yet or does not seem them for whatever reason. Eclipse has a similar problem.

Do you have incremental compiling turned on?

The second one is a guessing attempt based on where the APT filer thinks its CWD is.

What I probably need to do is use StandardLocation.SOURCE_PATH for IDEA (which does not work for Eclipse or Maven)... fun am I right?

Anyway you can see that logic here
https://github.com/jstachio/jstachio/blob/main/compiler/apt/src/main/java/io/jstach/apt/TextFileObject.java

I'll have a fix tonight or tomorrow.

In the meantime see or read: https://jstach.io/jstachio/io.jstach.jstache/io/jstach/jstache/JStache.html#RESOURCES_PATH_OPTION

I need to improve the overview to point to that.

@agentgt agentgt added bug Something isn't working documentation Improvements or additions to documentation good first issue Good for newcomers intellij labels Aug 10, 2023
@taypo
Copy link
Author
taypo commented Aug 10, 2023

I've read TextFileObject.java before I filed this, I don't envy you :)

@agentgt
Copy link
Contributor
agentgt commented Aug 11, 2023

Darn I'm having a hard time reproducing. Perhaps there are some symlinks (aka ln -s) ?

@taypo
Copy link
Author
taypo commented Aug 11, 2023

No symlinks in my path. Steps to reproduce:

  1. clone https://github.com/dsyer/java-template-demo.git
  2. checkout jstachio branch
  3. change version to 1.3.0 in pom.xml
  4. open in IDEA and let it load the project
  5. hit Cmd+F9 to build using the ide, and you'll get the error.

If you use the maven tool window to build, or your IDEA is set to delegate build to maven, then it works without issue. Maybe check here to see if your build is delegated to maven:
https://www.jetbrains.com/help/idea/delegate-build-and-run-actions-to-maven.html#delegate_to_maven

@agentgt
Copy link
Contributor
agentgt commented Aug 11, 2023

I think the critical step I missed is upgrade to 1.3.0

8000

@agentgt
Copy link
Contributor
agentgt commented Aug 11, 2023

I tried upgrading 1.3.0 and made sure delegate to maven is off.

I tailed the intellij log file as well as checked build output.

I only get one warning:

Output path /Users/agent/projects/java-template-demo/target/generated-sources/annotations intersects with a source root. Only files that were created by build will be cleaned.

I'm not sure what that means exactly. Maybe that is the issue? Is this CE or Ultimate?


macOs

IntelliJ IDEA 2023.2 (Community Edition)
Build #IC-232.8660.185, built on July 26, 2023
Runtime version: 17.0.7+7-b1000.6 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 12.4
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 4
Metal Rendering is ON
Registry:
ide.experimental.ui=true

Kotlin: 232-1.9.0-IJ8660.185

@taypo
Copy link
Author
taypo commented Aug 14, 2023

Its CE. Anything I can do to help?

@agentgt
Copy link
Contributor
agentgt commented Aug 14, 2023

One thing I did not try is change the pom before import of project.

I changed the pom after I imported.

I will try that in a little bit.

@agentgt
Copy link
Contributor
agentgt commented Aug 14, 2023

Its CE. Anything I can do to help?

I guess where do you see the error? Is it in the Build Output window or is in the actual intellij log file?

Does the error eventually go away?

I assume you are on macOS. Intel or Arm (I know its highly unlike this matters)?

Do you have another machine or vm image you could try?

I don't have intellij in front of me at the moment and won't be able to test till tonight.

@taypo
Copy link
Author
taypo commented Aug 14, 2023

It's in the build output. I'm using arm Mac. I can try on an intel mac later today. Let me see if I have a VM lying around.

@taypo
Copy link
Author
taypo commented Aug 15, 2023

I've tried with a windows and ubuntu VM, both had the same error.

@agentgt
Copy link
Contributor
agentgt commented Aug 15, 2023

Ok so I downloaded latest CE on my macOS ARM (the previous one I tested on was Intel).

Followed all the steps.

Here is my build output:

Executing pre-compile tasks…
Cleaning output directories…
Running 'before' tasks
Checking sources
Copying resources... [demo]
Parsing java… [demo]
java: Wrote services file: io.jstach.jstachio.spi.TemplateProvider
java: Wrote services file: io.jstach.jstachio.spi.JStachioExtension
Writing classes… [demo]
Updating dependency information… [demo]
Adding nullability assertions… [demo]
Adding threading assertions… [demo]
Adding pattern assertions… [demo]
Parsing java… [tests of demo]
Writing classes… [tests of demo]
Updating dependency information… [tests of demo]
Adding nullability assertions… [tests of demo]
Adding threading assertions… [tests of demo]
Adding pattern assertions… [tests of demo]
Running 'after' tasks
javac 20.0.1 was used to compile java sources
Finished, saving caches…
Executing post-compile tasks…
Finished, saving caches…
Synchronizing output directories…
8/15/23, 11:06 AM - Build completed successfully in 1 sec, 895 ms

Screen Shot 2023-08-15 at 11 10 56 AM

Screen Shot 2023-08-15 at 11 14 04 AM

The only thing I can currently think of is I picked JDK 20.

@agentgt
Copy link
Contributor
agentgt commented Aug 15, 2023

Can you copy the build output?

@agentgt
Copy link
Contributor
agentgt commented Aug 15, 2023

OK I got it to happen.

@agentgt
Copy link
Contributor
agentgt commented Aug 15, 2023

I switched to JDK 17 and it happened.

EDIT

So I can reproduce it readily by using JDK 17. If I use 18 or higher the problem goes away.

(btw I really appreciate your patience on this and am sorry I was not able to reproduce so easily!)

Sadly I'm not sure what the solution is yet other than telling people to use a newer JDK.

@agentgt
Copy link
Contributor
agentgt commented Aug 15, 2023

@taypo Can you try using JDK 20 and see if the problem goes away on your end while I figure out what hack I can put in?

@taypo
Copy link
Author
taypo commented Aug 15, 2023

Yeah, it worked now with JDK 20.
(nothing to be sorry about, I thought this was an IDEA issue, so didn't think to report my JDK version)

@agentgt
Copy link
Contributor
agentgt commented Aug 15, 2023

I found the problem and fixed it. The fallback was thinking it was Gradle because Intellij has Gradle somewhere in its execution command.

As for why it happens on JDK 17 there appears to be a bug where Intellij is not copying resources over for that JDK. Eclipse does this as well and it is a known issue hence all that fallback logic.

@agentgt
Copy link
Contributor
agentgt commented Aug 15, 2023

@taypo in Release 1.3.1 which just got released. May have to wait a little for Maven Central.

Thanks for the help!

agentgt added a commit to agentgt/jstachio that referenced this issue Sep 9, 2023
agentgt added a commit that referenced this issue Sep 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation good first issue Good for newcomers integration intellij
Projects
None yet
Development

No branches or pull requests

2 participants
0