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

regression: autobuild doesn't watch resources #1834

Closed
rothfels opened this issue Mar 17, 2021 · 12 comments
Closed

regression: autobuild doesn't watch resources #1834

rothfels opened this issue Mar 17, 2021 · 12 comments
Assignees

Comments

@rothfels
Copy link

rothfels commented Mar 17, 2021

We have a .classpath like this:

<classpath>
	<classpathentry kind="src" output="target/classes" path="src/main/java">
		<attributes>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>
	<classpathentry kind="src" output="target/classes" path="src/main/resources">
		<attributes>
			<attribute name="maven.pomderived" value="true"/>
		</attributes>
	</classpathentry>
        ...

Until recently, the Java language server would automatically update target/classes whenever files in src/main/resources would change. This was useful; we run a watch process in development to compile TS -> JS and output the generated code in src/main/resources.

Now, it seems only Java sources (in src/main/java) are being watched. The autobuild setting correctly generates new bytecode whenever .java files change. But it does not copy over resources that are updated.

We can work around this by putting our compiled resources directly in target/classes, but it seems like the language server should follow the classpath directives and do this automatically for us (as it used to). Instead, we now have to Java: Force Java Compilation (Full) to get the language server to copy over the resources whenever they change.

Environment
  • Operating System: MacOS 11.2.1
  • JDK version: openjdk 15.0.1 2020-10-20
  • Visual Studio Code version: 1.54.3
  • Java extension version: 0.76.0
@rubensa
Copy link

rubensa commented Mar 25, 2021

Looks like I have same problem. Whenever I change a Java source file, looks like the file is compiled (at least syntax is checked and any error in the file is reported) but the rest of the classes are not validated (If, for example, I change a method name, errors from other classes referencing the old name are not shown in the PROBLEMS tab). I have to Java: Force Java Compilation (Full) to get the errors.

Environment

  • Operating System: Ubuntu 20.04
  • JDK version: AdoptOpenJDK (build 11.0.10+9)
  • Visual Studio Code version: 1.54.3
  • Java extension version: 0.76.0

@snjeza
Copy link
Contributor

snjeza commented Mar 25, 2021

I can't reproduce the issue. Could you try the following:

@rubensa
Copy link

rubensa commented Mar 26, 2021

Looks like that fixed my problem. Thanks @snjeza

@rothfels
Copy link
Author

@snjeza my issue is still reproducible after following your troubleshooting steps. I don't think I have the same problem as @rubensa; he's complaining about Java source files. My issue is about resources in src/main/resources, not Java sources in src/main/java (we're using the standard Maven directory layout).

After following your steps, I still see that updating a file in src/main/resources will not update target until you manually run Java: Force Java Compilation (Full). This was not always the case.

@snjeza
Copy link
Contributor

snjeza commented Mar 26, 2021

After following your steps, I still see that updating a file in src/main/resources will not update target until you manually run Java: Force Java Compilation (Full). This was not always the case.

@rothfels Could you attach your .project, .classpath and settings.json files?

@rothfels
Copy link
Author

rothfels commented Apr 16, 2021

Sorry for the delay @snjeza. I made a minimal example with our project configs.

However I cannot reproduce this issue in that project.

I dug a little deeper, I think there is something specific to our project causing this error:

(from the language server log)


!ENTRY org.eclipse.jdt.ls.core 4 0 2021-04-16 09:26:36.019
!MESSAGE Failed to build workspace.
!STACK 1
Java Model Exception: Java Model Status [jdt.ls-java-project does not exist]
	at org.eclipse.jdt.internal.core.JavaElement.newJavaModelException(JavaElement.java:583)
	at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:254)
	at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:596)
	at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:326)
	at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:312)
	at org.eclipse.jdt.internal.core.JavaElement.getChildren(JavaElement.java:267)
	at org.eclipse.jdt.internal.core.JavaProject.getPackageFragmentRoots(JavaProject.java:2322)
	at org.eclipse.jdt.internal.core.JavaProject.getPackageFragments(JavaProject.java:2346)
	at org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.cleanupResources(ProjectsManager.java:212)
	at org.eclipse.jdt.ls.core.internal.handlers.BuildWorkspaceHandler.buildWorkspace(BuildWorkspaceHandler.java:53)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$25(JDTLanguageServer.java:817)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$50(JDTLanguageServer.java:989)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642)
	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:479)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

...

!ENTRY org.eclipse.core.jobs 4 2 2021-04-16 09:06:57.377
!MESSAGE An internal error occurred during: "Register Watchers".
!STACK 0
java.lang.IllegalArgumentException: URI is not hierarchical
	at java.base/java.io.File.<init>(File.java:421)
	at org.eclipse.jdt.ls.core.internal.managers.StandardProjectsManager.addWatcher(StandardProjectsManager.java:479)
	at org.eclipse.jdt.ls.core.internal.managers.StandardProjectsManager.registerWatchers(StandardProjectsManager.java:404)
	at org.eclipse.jdt.ls.core.internal.managers.StandardProjectsManager$1.run(StandardProjectsManager.java:107)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

!ENTRY org.eclipse.jdt.ls.core 1 0 2021-04-16 09:06:57.392
!MESSAGE >> registerWatchers'

!ENTRY org.eclipse.core.jobs 4 2 2021-04-16 09:06:57.394
!MESSAGE An internal error occurred during: "Initialize workspace".
!STACK 0
java.lang.IllegalArgumentException: URI is not hierarchical
	at java.base/java.io.File.<init>(File.java:421)
	at org.eclipse.jdt.ls.core.internal.managers.StandardProjectsManager.addWatcher(StandardProjectsManager.java:479)
	at org.eclipse.jdt.ls.core.internal.managers.StandardProjectsManager.registerWatchers(StandardProjectsManager.java:404)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer$2.run(JDTLanguageServer.java:309)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

If this is not a general problem, feel free to close the issue.

If you have recommendations to help me identify the file/resource(s) in our project causing this failure, please let me know. :)

@rothfels
Copy link
Author

rothfels commented Apr 16, 2021

More debugging info:

Our Java project root is actually in a subdirectory of our repo/workspace: ${workspaceFolder}/java

If I open the Java project root in VS Code, the file watcher initializes properly.

Is there a way to set the Java project root for the language server?

Perhaps this isn't a bug, but I think it's a regression from previous behavior. We didn't have problems with the file watcher until somewhat recently, whereas our project structure has been static for quite some time. We've always had our VS Code workspace root one directory above our Java project directory.

@snjeza
Copy link
Contributor

snjeza commented Apr 16, 2021

@rothfels could you attach your settings. json or the java.format.settings.url property?

@rothfels
Copy link
Author

rothfels commented Apr 17, 2021

"java.format.settings.url": "file:developers/code-style.xml",

^ we modified it to work around #1827

Workspace structure:

${workspaceFolder}
|__ java 
|__ developers 
...

(moving the formatter settings into the java project root doesn't fix the issue)

@rothfels
Copy link
Author

Removing java.format.settings.url fixes the problem, so pretty clear the regression is from #1827

@snjeza snjeza self-assigned this Apr 17, 2021
@snjeza
Copy link
Contributor

snjeza commented Apr 17, 2021

@rothfels Could you try

"java.format.settings.url": "developers/code-style.xml",

@rothfels
Copy link
Author

rothfels commented Apr 17, 2021

@snjeza yes, that also fixes the problem. Thank you! 🎉

@snjeza snjeza closed this as completed Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants