redhat-developer / redhat-developer/vscode-java

[Question] What does actually happen when a project (with a pom.xml) is built?

Offen
#1,354 1 Kommentar 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Maven question
Vorherrschende Sprache
TypeScript
Sterne
2.3k
Forks
546
Ø Merge
20 Std. 1 Min.
Gemergte PRs (30 T.)
11

Beschreibung

I have some difficulties understanding what really happens when the Java Language Server starts upon opening my project on VS Code and when I save a modified .java file afterward.

My question concerns specifically the building of the project, and I'm asking it because I've witnessed behavior that I couldn't quite explain.

My project is a Maven project and thus, has a pom.xml file. In this file, I use some plugins in the <build> node that do some heavy work (in my case, installing npm dependencies for my frontend and building it).

<!-- An excerpt of my pom.xml file -->
<?xml version="1.0" encoding="UTF-8" ?>
<project /* ... */>
  <build>
    /* ... */
    <plugins>
      <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <version>1.9.1</version>
        <executions>
          <execution>
            /* install nodejs and npm */
          </execution>
          <execution>
            /* npm ci */
          </execution>
          <execution>
            /* npm run build */
          </execution>
        </executions>
      </plugin>
      /* other plugins */
    </plugins>
  /* ... */
  </build>
</project>

When I open the project with VS Code, the Java Language Server starts and eventually builds the project. This build phase takes a hefty amount of time to complete but envetually does so. After that, each time I save a .java file, the Java Language Server hops in and starts building the project again (as it is somewhat expected). This build also takes a huge amount of time before completing.

When commenting the <plugin> node in my `pom.xml that do the heavy work, the building of the project runs incredibly faster.

Of this, I've come to the conclusion that the Java Language Server detects that I'm using a Maven project thanks to the presence of the pom.xml file and delegates the building of the project to M2Eclipse which, in turn, does something like mvn compile, meaning that each build will execute all the goals registered on the <build> node.

Am I right in this assertion? And if so, would there be any way to compile the project as a "simple" Java Application (something like IntelliJ's Application configuration)?

I know that I could use Maven profiles to scope the execution of those plugins' goals, and prevent their execution when developping but I'd like to be sure to understand what is happening under the hood.

Environment
  • Operating System: WSL
  • JDK version: 11
  • Visual Studio Code version: 1.43.2
  • Java extension version: 0.59.0

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Nachvollziehen, wie der Java Language Server ein Maven-Projekt mit einer pom.xml verarbeitet, einschließlich der Frage, ob M2Eclipse die konfigurierten Plugin-Ausführungen während des Starts und beim Speichern von Java-Dateien aufruft. Den beobachteten Build-Ablauf und die Frage dokumentieren, ob ein einfacher Java-Kompilierungsmodus unterstützt wird, wobei das Maven-Plugin-Beispiel des Issues als erwartetes Szenario verwendet wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java, vscode
Bereich
build-system, developer-experience
Issue-Typ
Dokumentation
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.