redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.07k stars 433 forks source link

Building a project never finishes #3639

Closed tsaarni closed 2 months ago

tsaarni commented 5 months ago

Background:

I'm working on Keycloak using vscode-java. This project has proven to be quite challenging before, and unfortunately I now again have new problems that I'd kindly ask for help to troubleshoot.

The problem:

When opening the project the Java build never finishes. The constant re-compilation on the background will consume considerable CPU resources and heat up the machine.

The project builds correctly from command line using mvn.

Environment
Steps To Reproduce
  1. git clone https://github.com/keycloak/keycloak.git
  2. cd keycloak
  3. mvn clean install -DskipTestsuite -DskipExamples -DskipTests
  4. open vscode
  5. observe jdt starting to build the project but getting into infinite loop
Current Result

The loop that gets executed again and again consists of following sequence of maven modules (grepping from logs):

  message: '[Info  - 2:28:33 PM] May 3, 2024, 2:28:32 PM Built project keycloak-parent in 3798 ms',
  message: '[Info  - 2:28:34 PM] May 3, 2024, 2:28:34 PM Built project keycloak-admin-ui in 1665 ms',
  message: '[Info  - 2:28:34 PM] May 3, 2024, 2:28:34 PM Built project keycloak-distribution-licenses-common in 4 ms',
  message: '[Info  - 2:28:34 PM] May 3, 2024, 2:28:34 PM Built project keycloak-distribution-parent in 1 ms',
  message: '[Info  - 2:28:34 PM] May 3, 2024, 2:28:34 PM Built project keycloak-js-adapter in 3 ms',
  message: '[Info  - 2:28:34 PM] May 3, 2024, 2:28:34 PM Built project keycloak-js-admin-client in 48 ms',
  message: '[Info  - 2:28:35 PM] May 3, 2024, 2:28:35 PM Built project keycloak-js-parent in 479 ms',
  message: '[Info  - 2:28:36 PM] May 3, 2024, 2:28:36 PM Built project keycloak-account-ui in 1605 ms',
  message: '[Info  - 2:28:36 PM] May 3, 2024, 2:28:36 PM Built project keycloak-distribution-licenses-common in 5 ms',
  message: '[Info  - 2:28:36 PM] May 3, 2024, 2:28:36 PM Built project keycloak-distribution-parent in 1 ms',
  message: '[Info  - 2:28:36 PM] May 3, 2024, 2:28:36 PM Built project keycloak-js-parent in 1 ms',
  message: '[Info  - 2:28:40 PM] May 3, 2024, 2:28:40 PM Built project keycloak-parent in 3745 ms',
  message: '[Info  - 2:28:42 PM] May 3, 2024, 2:28:42 PM Built project keycloak-admin-ui in 1718 ms',
  message: '[Info  - 2:28:42 PM] May 3, 2024, 2:28:42 PM Built project keycloak-distribution-licenses-common in 6 ms',
  message: '[Info  - 2:28:42 PM] May 3, 2024, 2:28:42 PM Built project keycloak-distribution-parent in 1 ms',
  message: '[Info  - 2:28:42 PM] May 3, 2024, 2:28:42 PM Built project keycloak-js-adapter in 5 ms',
  message: '[Info  - 2:28:42 PM] May 3, 2024, 2:28:42 PM Built project keycloak-js-admin-client in 49 ms',
  message: '[Info  - 2:28:42 PM] May 3, 2024, 2:28:42 PM Built project keycloak-js-parent in 486 ms',
  message: '[Info  - 2:28:44 PM] May 3, 2024, 2:28:44 PM Built project keycloak-account-ui in 1663 ms',
  message: '[Info  - 2:28:44 PM] May 3, 2024, 2:28:44 PM Built project keycloak-distribution-licenses-common in 5 ms',
  message: '[Info  - 2:28:44 PM] May 3, 2024, 2:28:44 PM Built project keycloak-distribution-parent in 0 ms',
  message: '[Info  - 2:28:44 PM] May 3, 2024, 2:28:44 PM Built project keycloak-js-parent in 1 ms',

it will then start from the keycloak-parent again, and continue forever, trying to build this set of modules. I'm not able to identify the reason why the build is (re)triggered again and again.

Here are some log files from build:

Expected Result

Build should finish.

Additional Informations

I'm enabled following logs in .vscode/settings.json

  "java.jdt.ls.vmargs": "-Dlog.level=ALL -Djdt.ls.debug=true -Dmaven.plugin.validation=verbose -Xmx16G -Xms100m",
  "java.trace.server": "verbose",

I've also tried excluding submodules by adding following in .vscode/settings.json but build still gets stuck in the same way, even though in theory the looping modules should not even be imported anymore

  "java.import.exclusions": [
        "**/node_modules/**",
        "**/node/**",
        "**/js/**",
        "**/distribution/**",
        "**/themes/**"
  ]

Some time ago I could open the project without infinite build loop. I did not use exclusions or any other workarounds in settings. At the moment, I do not yet know if my problem appeared after changes in Keycloak code or possibly after vscode-java update, or something else.

rgrunber commented 5 months ago

I'm able to reproduce this as well, though I needed -Xmx4G instead of 1G for java.jdt.ls.vmargs to fully import.

The thing that immediately stood out, and which I saw in my logs as well is :

{   
  message: "[Trace - 10:30:08] Sending notification 'workspace/didChangeWatchedFiles'.",
  level: 'info',
  timestamp: '2024-05-03 10:30:08.190'
}
{
  message: 'Params: {\n' +
    '    "changes": [\n' +
    '        {\n' +
    '            "uri": "file:///home/rgrunber/sample-projects/keycloak/distribution/licenses-common/target/classes/keycloak-licenses-common/LICENSE.txt",\n' +
    '            "type": 2\n' +
    '        }\n' +
    '    ]\n' +
    '}\n' +
    '\n',
  level: 'info',
  timestamp: '2024-05-03 10:30:08.190'
}

Other than progress & diagnostic notifications, I didn't see anything else in the build process that might be responsible for triggering a rebuild.

I think https://github.com/eclipse-jdtls/eclipse.jdt.ls/blob/d6bc183c77428d586b58fe8a5afcd8bd4bc98f20/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JDTUtils.java#L1266 ( https://github.com/eclipse-jdtls/eclipse.jdt.ls/pull/1207 ) might be responsible since I can stop the cycle just by setting the parent to null.

The pom is https://github.com/keycloak/keycloak/blob/main/distribution/licenses-common/pom.xml and the configuration is handled by build-helper-maven-plugin.

@snjeza , any idea why this happens or how we could deal with it ?

snjeza commented 4 months ago

~~The issue is caused by the maven-antrun-plugin plugin. It creates a java project and restarts the build. A workaround~~

 "java.configuration.maven.defaultMojoExecutionAction": "ignore",`

You can also try VS Code 1.32.0. See https://github.com/eclipse-jdtls/eclipse.jdt.ls/pull/3150

tsaarni commented 4 months ago

Thanks @snjeza and @rgrunber!

I tried both:

but for some reason, these did not help for me. I still end up in build that never finishes.

As @rgrunber pointed out license file generation, I now tested removing following lines from Keycloak https://github.com/keycloak/keycloak/blob/6a38be6239ad9dad7fb0c4941c117eddadc7958b/distribution/licenses-common/pom.xml#L30-L44. That allowed me to open and build the project again, so it is true that it is the culprit.

rgrunber commented 4 months ago

I tried https://github.com/eclipse-jdtls/eclipse.jdt.ls/pull/3150 as well and it didn't stop the build loop. I tried with a clear workspace cache for the keycloak project. The default is definitely ignore for java.configuration.maven.defaultMojoExecutionAction so it had no effect.

It could just be that the issues fixed there have no effect here.

Update: Ok, I saw one instance where the build loop stopped after maybe about 6 consecutive build operations. I think I'd have to run this some more times before/after the change to see if it actually improves it or if there's some chance the build loop doesn't occur.

snjeza commented 4 months ago

@rgrunber You are right. The keycloak project has other issues. However, https://github.com/eclipse-jdtls/eclipse.jdt.ls/pull/3150 should help. Did you try the following:

$ cd keycloak
$ code .
wait for the build to finish
reload the VS Code window (this step should be much faster with #3150)

The build should also be faster because we postponed workspace/didChangeWatchedFiles after finishing the build. See https://github.com/eclipse-jdtls/eclipse.jdt.ls/pull/3150/commits/cfb076c10a86523d734942f29364d0d90aa6634f#diff-a5ac9de1e29f9f41ff8198d1422328687328e9daacea58594ecd68b4ecde2311R61

snjeza commented 4 months ago

... or if there's some chance the build loop doesn't occur.

I will check.

rgrunber commented 3 months ago

I tried this out with the latest pre-release and am still seeing the build loop for keycloak. @snjeza let me know if you see this as well. Is there anything we can do ?

Here's what I noticed (note the timestamps) :

[Trace - 15:24:49] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///home/rgrunber/sample-projects/keycloak/saml-core/src/test/java/org/keycloak/saml/common/util/StaxParserUtilTest.java",
    "diagnostics": [
        {
            "range": {
                "start": {
                    "line": 51,
                    "character": 67
                },
                "end": {
                    "line": 51,
                    "character": 73
                }
            },
            "severity": 2,
            "code": "67108967",
            "source": "Java",
            "message": "The method none() from the type ExpectedException is deprecated",
            "tags": [
                2
            ]
        }
    ]
}

[Trace - 15:27:19] Received request 'window/workDoneProgress/create - (29)'.
Params: {
    "token": "17a78d3e-ac88-4893-8b16-7768fc282144"
}

[Trace - 15:27:19] Sending response 'window/workDoneProgress/create - (29)'. Processing request took 0ms
No result returned.

[Trace - 15:27:19] Received notification '$/progress'.
Params: {
    "token": "17a78d3e-ac88-4893-8b16-7768fc282144",
    "value": {
        "kind": "begin",
        "title": "Building",
        "message": "Building"
    }
}

The language server completed the build, sent the diagnostics, and was quiet for a few minutes. I didn't perform any actions, and could hear that my fans had spun down after the initial build. Then, the build job started for no reason I could see.

snjeza commented 3 months ago

let me know if you see this as well. Is there anything we can do ?

@rgrunber I'm checking

snjeza commented 3 months ago

I tried this out with the latest pre-release and am still seeing the build loop for keycloak. @snjeza let me know if you see this as well. Is there anything we can do ?

I can't can reproduce the issue.

Steps to reproduce:

$ cd <keyloack>
$ ./mvnw clean
$ rm -rf ~/.config/Code/User/workspaceStorage/
$ rm -rf `find . -name .project `; rm -rf `find . -name .classpath `; rm -rf `find . -name .settings`
$ git clean -fd
$ code .

@rgrunber could you try to add the following property to settings.json

"java.import.exclusions": [
        "**/node_modules/**",
        "**/.metadata/**",
        "**/archetype-resources/**",
        "**/META-INF/maven/**",
        "**/keycloak/**",
        "**/keycloak",
        "!**/keycloak/core",
        "!**/keycloak/common",
        "!**/keycloak/boms",
        "!**/keycloak/boms/**",
        "!**/keycloak/adapters",
        "!**/keycloak/adapters/**",
        "!**/keycloak/authz",
        "!**/keycloak/authz/**",
        "!**/keycloak/crypto",
        "!**/keycloak/crypto/**",
        "!**/keycloak/dependencies",
        "!**/keycloak/dependencies/**",
        "!**/keycloak/examples",
        "!**/keycloak/examples/**",
        "!**/keycloak/federation",
        "!**/keycloak/federation/**",
        "!**/keycloak/integration",
        "!**/keycloak/integration/**",
        "!**/keycloak/model",
        "!**/keycloak/model/**",
        "!**/keycloak/operator",
        "!**/keycloak/operator/**",
        // ... You can add any keycloak subfolder other than distribution, js, node , node_modules.
    ],
snjeza commented 3 months ago

I tried this out with the latest pre-release and am still seeing the build loop for keycloak.

~~The null analysis can cause the build loop. One workaround is to set "java.compile.nullAnalysis.mode": "disabled"~~ I'm preparing a fix.

snjeza commented 3 months ago

The issue is an upstream m2e issue. It happens when m2e can't configure the project's classpath. m2e configures the Java Nature and Builder but doesn't configure the classpath.

You can try to import test3639.zip You will notice that the project contains .project with the Java nature and builder but doesn't contain .classpath.

keycloak includes one similar project as described at https://github.com/redhat-developer/vscode-java/issues/3639#issuecomment-2093437052

rgrunber commented 2 months ago

v1.33.2024072008 from the pre-releases should contain the fix.