vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

Working Maven project reports multiple errors in VSCode and will not build

Open Ettery opened this issue 6 years ago • 60 comments

I have a simple working Java Maven project. This project builds (assuming you have Java and Maven setup) - with:

mvn clean install

And the jar file runs as expected.

However, when I open it in VSCode (I have the Java Extension pack installed) - I see 105 "Problems" reported in the pom.xml:

  • 4x "Failed to read artifact descriptor for ..."
  • The rest "Missing artifact ..."

This appears to prevent most of the VSCode Java tools from working - I can't build and debug. Intellisense seems to be sketchy/intermittent. And so on.

Environment
  • Operating System: Windows 10
  • JDK version: OpenJDK 11.0.5.10
  • Visual Studio Code version: 1.41.1
  • Java extension version: 0.55.0
Steps To Reproduce
  1. Extract the attached zip file to a folder
  2. Open the folder in VSCode and inspect the Problems tab
  3. Attempt to build the project

vsc-java-test.zip

To prove Maven works
  1. Extract the attached zip file to a folder
  2. Open a bash or cmd window, cd to the folder and run mvn clean install
  3. Copy the generated thularest-1.0.jar file from <folder>/target to <folder>/bin
  4. cd to /bin and run ./rest-start.sh
  5. Crowse to http://localhost:8080/api/hello

Ettery avatar Jan 09 '20 11:01 Ettery

works for me. Have you tried to execute the "Clean the Java language server workspace" command?

fbricon avatar Jan 09 '20 12:01 fbricon

I have. It clears and says "No problems", but as soon as I open a Java file it generates the 105 problems in pom.xml again.

What JDK are you using, and could that be a problem?

Thanks.

Ettery avatar Jan 09 '20 14:01 Ettery

Same problem here, fully functional project on eclipse, tons os errors in VS Code.

dbnicacio avatar Feb 27 '20 15:02 dbnicacio

the sample project works for me. macOSX, OpenJDK 11.0.6. Can you try extract the zip file to another new place, and open it in vscode see if it works?

Another casual guess is, are you opening the same project in both Eclipse and VS Code?

Eskibear avatar Feb 27 '20 16:02 Eskibear

Facing the same issue with a huge project. I have checked by creating different workspaces for eclipse and vscode. Maven build (mvn clean compile) succeeds, eclipse also compiles the project successfully but vscode shows more than 40K errors like:

  1. The import cannot be resolved.
  2. ClassName cannot be resolved to a type and many more.

If I open the file, compilation errors in that perticular file resolves automatically but when the window is reloaded the errors come back.

I think this started happening after 1.40 or 1.41.

This has forced me to move unwillingly back to eclipse.

OS: Ubuntu 19.10 x86_64 java version "1.8.0_231" Java(TM) SE Runtime Environment (build 1.8.0_231-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode) Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /opt/apache-maven/apache-maven-3.6.3 Java version: 1.8.0_231, vendor: Oracle Corporation, runtime: /opt/java/jdk1.8.0_231/jre Default locale: en_GB, platform encoding: UTF-8 OS name: "linux", version: "5.3.0-42-generic", arch: "amd64", family: "unix"

Version: 1.43.2 Commit: 0ba0ca52957102ca3527cf479571617f0de6ed50 Date: 2020-03-24T07:52:11.516Z Electron: 7.1.11 Chrome: 78.0.3904.130 Node.js: 12.8.1 V8: 7.8.279.23-electron.0 OS: Linux x64 5.3.0-42-generic

manishbhalshankar avatar Mar 25 '20 05:03 manishbhalshankar

I face the same issue, however, it happens only within my company, not at home. @manishbhalshankar you mentioned "huge project"....is that at your work? I'm not sure if that's a factor here. In my case, we have an internal Maven repository server, instead of the public repo (https://repo.maven.apache.org/maven2).

alantango avatar Apr 03 '20 03:04 alantango

Hi Alantango, Yes, it is my work project and we use both, internal as well as central repo. This used to work properly till vscode version 1.38-1.40 (not sure on the exact versin no.)

manishbhalshankar avatar Apr 05 '20 10:04 manishbhalshankar

@manishbhalshankar I raised a separate thread #1365 here yesterday too:

https://github.com/redhat-developer/vscode-java/issues/1365

alantango avatar Apr 05 '20 12:04 alantango

@manishbhalshankar I believe the solution that resolved #1365 would work for you too. Suggest you give it a try.

alantango avatar Apr 05 '20 22:04 alantango

@alantango no that solution did not work for me. I have now downgraded Language support for Java ™ by Red Hat to version 0.55.1. No compilation errors are now reported. There was some change done in v0.56.0 which is causing issues with legacy maven projects with multiple modules and submodules.

manishbhalshankar avatar Apr 06 '20 14:04 manishbhalshankar

@manishbhalshankar ok....I'm using v0.59.1 which I believe it's the latest.

alantango avatar Apr 06 '20 17:04 alantango

Yes, thats the latest version. I am facing issues with all versions after v0.55.1

manishbhalshankar avatar Apr 06 '20 18:04 manishbhalshankar

Can anyone suggest on how we can proceed further in getting this issue resolved?

manishbhalshankar avatar Apr 08 '20 18:04 manishbhalshankar

@manishbhalshankar could you provide your VS Code settings.json, maven settings.xml, project's pom.xml?

snjeza avatar Apr 08 '20 18:04 snjeza

It is a huge multi-module project. I am attaching the pom.xml of the module in which I am getting compilation errors. pom-settings.zip

manishbhalshankar avatar Apr 11 '20 05:04 manishbhalshankar

@manishbhalshankar could you try to remove the following property:

"java.configuration.runtimes": [
        {
            "name": "JavaSE-1.8",
            "path": "/opt/java/jdk1.8.0_231",
            "default": true
        }
    ],

Could you also attach server logs - https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#turn-on-message-tracing-between-vs-code-and-the-java-language-server

snjeza avatar Apr 11 '20 15:04 snjeza

@snjeza Removing "java.configuration.runtimes" didnot help. Could you please suggest how I can write the Languate supprot for Java output log to a file as the complete log in not available at the end of the process in output view.

Also, is it possible to share the logs only with you instead of sharing it here?

manishbhalshankar avatar Apr 11 '20 18:04 manishbhalshankar

Could you please suggest how I can write the Languate supprot for Java output log to a file as the complete log in not available at the end of the process in output view.

Ctrl+Shift+P > Java: Open all log files

Also, is it possible to share the logs only with you instead of sharing it here?

My email address is [email protected]

snjeza avatar Apr 11 '20 18:04 snjeza

@snjeza I have emailed you the logs. Please suggest further.

manishbhalshankar avatar Apr 11 '20 20:04 manishbhalshankar

@manishbhalshankar could you try to disable other Java related extensions?

snjeza avatar Apr 11 '20 21:04 snjeza

@snjeza I tried the following combinations but still the same issue:

  1. Disabled spring boot extension pack and from Java extension pack, kept only Maven for java and Language support for Java enabled.
  2. Kept only Language support for Java enabled and disabled all other java related extensions.

In both the cases, I performed the Clean Java LS workspace.

manishbhalshankar avatar Apr 12 '20 17:04 manishbhalshankar

Kept only Language support for Java enabled and disabled all other java related extensions. I performed the Clean Java LS workspace.

@manishbhalshankar could you send your log files when only Java LS is enabled? Could you also send your .classpath and .settings/* files?

snjeza avatar Apr 12 '20 18:04 snjeza

@snjeza I have emailed you the requested files.

manishbhalshankar avatar Apr 12 '20 19:04 manishbhalshankar

@snjeza Thanks a lot for helping me in resolving the compilation errors in my project.

Here is a reference for others who might have similar problem and this solution might help them as well:

  1. Maven project file pom.xml should be properly setup as per the latest maven conventions.
  2. Need to understand the process of maven build. What all tasks maven performs related to resources and src.
  3. Need to understand how any IDE compiles your project.

In my case, the errors were caused by the CVS version control folders and adding the following entry in my project's pom resolved them:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>

            <configuration>
                <excludes>
                    <exclude>**/CVS/*</exclude>
                </excludes>
            </configuration>
        </plugin>
    </plugins>
</build>

This also helped me in resolving the resources not available issue when project is compiled through any IDE. The cause of this issue is the excluding="**" entry that gets added to the .classpath file for src/main/resources. Adding the following entry to my project's pom resolved the issue. The excluding="**" attribute is still there but resources are now available in target folder.

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.1.0</version>

    <executions>
        <execution>
            <id>copy-resources</id>
            <phase>compile</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>

            <configuration>
                <outputDirectory>${project.build.directory}/classes</outputDirectory>
                <resources>
                    <resource>
                        <directory>src/main/resources/</directory>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

manishbhalshankar avatar Apr 22 '20 16:04 manishbhalshankar

I have the same issue, I get the following error in the language server, it seems it's not correctly reading and applying password authentication from the maven settings file:

Failure to transfer com.sun.xml.fastinfoset:FastInfoset:jar:1.2.12 from https://***.jfrog.io/***/maven-release was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact com.sun.xml.fastinfoset:FastInfoset:jar:1.2.12 from/to central (https://***.jfrog.io/***/maven-release): Access denied to https://***.jfrog.io/***/maven-release/com/sun/xml/fastinfoset/FastInfoset/1.2.12/FastInfoset-1.2.12.jar. Error code 403, Forbidden

org.eclipse.aether.transfer.ArtifactTransferException: Failure to transfer com.sun.xml.fastinfoset:FastInfoset:jar:1.2.12 from https://***.jfrog.io/***/maven-release was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact com.sun.xml.fastinfoset:FastInfoset:jar:1.2.12 from/to central (https://***.jfrog.io/***/maven-release): Access denied to https://***.jfrog.io/***/maven-release/com/sun/xml/fastinfoset/FastInfoset/1.2.12/FastInfoset-1.2.12.jar. Error code 403, Forbidden
	at org.eclipse.aether.internal.impl.DefaultUpdateCheckManager.newException(DefaultUpdateCheckManager.java:225)
	at org.eclipse.aether.internal.impl.DefaultUpdateCheckManager.checkArtifact(DefaultUpdateCheckManager.java:193)
	at org.eclipse.aether.internal.impl.DefaultArtifactResolver.gatherDownloads(DefaultArtifactResolver.java:559)
	at org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:483)
	at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:401)
	at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:229)
	at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:340)
	at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:202)
	at org.apache.maven.project.DefaultProjectBuilder.resolveDependencies(DefaultProjectBuilder.java:227)
	at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:200)
	at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:124)
	at org.eclipse.m2e.core.internal.embedder.MavenImpl.readMavenProject(MavenImpl.java:629)
	at org.eclipse.m2e.core.internal.project.registry.DefaultMavenDependencyResolver.resolveProjectDependencies(DefaultMavenDependencyResolver.java:65)
	at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refreshPhase2(ProjectRegistryManager.java:547)
	at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.lambda$3(ProjectRegistryManager.java:511)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:179)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:153)
	at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:509)
	at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:361)
	at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:312)
	at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.configureNewMavenProjects(ProjectConfigurationManager.java:265)
	at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.lambda$0(ProjectConfigurationManager.java:174)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:179)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:153)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:101)
	at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:1373)
	at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.importProjects(ProjectConfigurationManager.java:144)
	at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.importProjects(ProjectConfigurationManager.java:134)
	at org.eclipse.jdt.ls.core.internal.managers.MavenProjectImporter.importToWorkspace(MavenProjectImporter.java:210)
	at org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.importProjects(ProjectsManager.java:108)
	at org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.initializeProjects(ProjectsManager.java:98)
	at org.eclipse.jdt.ls.core.internal.handlers.InitHandler$1.runInWorkspace(InitHandler.java:195)
	at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:42)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

Here is my maven settings file (located in C:\Users\<me>\.m2\settings.xml):

<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <servers>
    <server>
      <username>***</username>
      <password>***</password>
      <id>central</id>
    </server>
    <server>
      <username>***</username>
      <password>***</password>
      <id>snapshots</id>
    </server>
  </servers>
  <profiles>
    <profile>
      <repositories>
        <repository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>maven-release</name>
          <url>https://***.jfrog.io/***/maven-release</url>
        </repository>
        <repository>
          <snapshots />
          <id>snapshots</id>
          <name>maven-snapshot</name>
          <url>https://***.jfrog.io/***/maven-snapshot</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>maven-release</name>
          <url>https://***.jfrog.io/***/maven-release</url>
        </pluginRepository>
        <pluginRepository>
          <snapshots />
          <id>snapshots</id>
          <name>maven-snapshot</name>
          <url>https://***.jfrog.io/***/maven-snapshot</url>
        </pluginRepository>
      </pluginRepositories>
      <id>artifactory</id>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>artifactory</activeProfile>
  </activeProfiles>
</settings>

The project compiles successfully with mvn compile or mvn package.

Operating System: Windows 10 JDK version: Amazon Corretto 11.0.7_10 Visual Studio Code version: 1.48.2 Java extension version: 0.65.0

bhgsbatista avatar Aug 31 '20 16:08 bhgsbatista

I face a similar issue with the hadoop (https://github.com/apache/hadoop) codebase, it compiles properly with mvn but vscode shows issues. Also, mvn sometimes even fails if vscode is open. If I close vscode, then mvn on cli completes successfully.

Note: I use runtime config as java 1.8 and jdk (java.home) as adopt jdk 14 (as LS requires newer jdk and hadoop requires 1.8).

108anup avatar Jan 14 '21 17:01 108anup

Same issue here. With opened VSCode, maven fails.

I have to remove the plugin to write java code.

Anybody found a fix?

pbassut avatar Feb 27 '21 06:02 pbassut

Same issue for me. A lot of "Missing artifact..." errors in pom.xml

Merteg avatar Apr 08 '21 13:04 Merteg

Same issue, my maven project is getting built but VS code is showing 1k errors.

ksushant881 avatar Jun 01 '21 19:06 ksushant881

Same issue, my maven project is getting built but VS code is showing 1k errors.

Issue resolved update Just download lombok annotations support extension in VS Code

ksushant881 avatar Jun 02 '21 12:06 ksushant881