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

during a maven build, reflections is invoked several times #20385

Closed
jorgheymans opened this issue Oct 30, 2024 · 2 comments · Fixed by #20465
Closed

during a maven build, reflections is invoked several times #20385

jorgheymans opened this issue Oct 30, 2024 · 2 comments · Fixed by #20465

Comments

@jorgheymans
Copy link

Description of the bug

Even though #19874 greatly improved things, each invocation of the vaadin maven plugin seems to still scan the classpath - according to the log output:

 [INFO] --- vaadin:24.5.2:prepare-frontend (default) @ ims ---
 [INFO] Reflections took 1624 ms to scan 320 urls, producing 17948 keys and 94028 values
 .....
 [INFO] 
 [INFO] >>> vaadin:24.5.2:build-frontend (default) > :configure @ ims >>>
 --- vaadin:24.5.2:configure (configure) @ ims ---
 [INFO] Reflections took 1712 ms to scan 320 urls, producing 17948 keys and 94028 values 
 ......
 [INFO] 
 [INFO] <<< vaadin:24.5.2:build-frontend (default) < :configure @ ims <<<
 [INFO] 
 [INFO] --- vaadin:24.5.2:build-frontend (default) @ ims ---
 [INFO] Reflections took 1341 ms to scan 320 urls, producing 17948 keys and 94028 values
 .....

Expected behavior

Ideally the classpath is scanned only once

Minimal reproducible example

A normal maven build of any vaadin project

Versions

Vaadin 24.5.2

@mcollovati
Copy link
Collaborator

mcollovati commented Oct 30, 2024

The main reason for that is that prepare-frontend and build-frontend can run on different phases, so having different "class path".
ClassFinder is now per mojo instances
We can check if it is possible to cache per execution phase.

Another thing that should be investigated is why build-frontend is reported twice
Never mind. The additional ClassFinder is because of the configure goal

@mshabarov mshabarov moved this to 🅿️Parking lot - under consideration in Vaadin Flow ongoing work (Vaadin 10+) Nov 5, 2024
mcollovati added a commit that referenced this issue Nov 12, 2024
Extracts logics from Flow mojos to separated task classes, loaded with a
custom class loader composed by project and plugin dependencies, with
the firsts having precedence on the others.
This make sure classes are always loaded from the same class loader,
preventing errors like having a class loaded by plugin class loader, but
one of its parent present only in project class loader (see #19616).
It also prevents retrieving resources from plugin dependency instead of
from same artifact defined in the project (see #19009).
This refactoring caches a ClassFinder per execution phase, so that it can be
reused by multiple goals configured to run on the same phase.
It also removes the need to instantiate a ClassFinder to checking for Hilla
classes, limiting the number or scans processed during the build.

Fixes #19616
Fixes #19009
Fixes #20385
mcollovati added a commit that referenced this issue Nov 13, 2024
Run Flow mojos using an isolated class loader that includes both project and
plugin dependencies, with project dependencies taking precedence. This ensures
that classes are always loaded from the same class loader at runtime, preventing
errors where a class might be loaded by the plugin's class loader while one of
its parent classes is only available in the project’s class loader (see #19616).

Additionally, this approach prevents the retrieval of resources from plugin
dependencies when the same artifact is defined within the project (see #19009).

This refactoring also introduces caching for ClassFinder instances per
execution phase, allowing multiple goals configured for the same phase to reuse
the same ClassFinder. It also removes the need to instantiate a ClassFinder
solely for Hilla class checks, reducing the number of scans performed during
the build.

Fixes #19616
Fixes #19009
Fixes #20385
mcollovati added a commit that referenced this issue Nov 13, 2024
Run Flow mojos using an isolated class loader that includes both project and
plugin dependencies, with project dependencies taking precedence. This ensures
that classes are always loaded from the same class loader at runtime, preventing
errors where a class might be loaded by the plugin's class loader while one of
its parent classes is only available in the project’s class loader (see #19616).

Additionally, this approach prevents the retrieval of resources from plugin
dependencies when the same artifact is defined within the project (see #19009).

This refactoring also introduces caching for ClassFinder instances per
execution phase, allowing multiple goals configured for the same phase to reuse
the same ClassFinder. It also removes the need to instantiate a ClassFinder
solely for Hilla class checks, reducing the number of scans performed during
the build.

Fixes #19616
Fixes #19009
Fixes #20385
@github-project-automation github-project-automation bot moved this from Maybe to Done / Pending Release in Vaadin Flow enhancements backlog (Vaadin 10+) Nov 20, 2024
@github-project-automation github-project-automation bot moved this from 🅿️Parking lot - under consideration to Done in Vaadin Flow ongoing work (Vaadin 10+) Nov 20, 2024
@github-project-automation github-project-automation bot moved this from 🅿️Parking lot - under consideration to Done in Vaadin Flow ongoing work (Vaadin 10+) Nov 20, 2024
mcollovati added a commit that referenced this issue Nov 20, 2024
Run Flow mojos using an isolated class loader that includes both project and
plugin dependencies, with project dependencies taking precedence. This ensures
that classes are always loaded from the same class loader at runtime, preventing
errors where a class might be loaded by the plugin's class loader while one of
its parent classes is only available in the project’s class loader (see #19616).

Additionally, this approach prevents the retrieval of resources from plugin
dependencies when the same artifact is defined within the project (see #19009).

This refactoring also introduces caching for ClassFinder instances per
execution phase, allowing multiple goals configured for the same phase to reuse
the same ClassFinder. It also removes the need to instantiate a ClassFinder
solely for Hilla class checks, reducing the number of scans performed during
the build.

Fixes #19616
Fixes #19009
Fixes #20385
mcollovati added a commit that referenced this issue Nov 20, 2024
Run Flow mojos using an isolated class loader that includes both project and
plugin dependencies, with project dependencies taking precedence. This ensures
that classes are always loaded from the same class loader at runtime, preventing
errors where a class might be loaded by the plugin's class loader while one of
its parent classes is only available in the project’s class loader (see #19616).

Additionally, this approach prevents the retrieval of resources from plugin
dependencies when the same artifact is defined within the project (see #19009).

This refactoring also introduces caching for ClassFinder instances per
execution phase, allowing multiple goals configured for the same phase to reuse
the same ClassFinder. It also removes the need to instantiate a ClassFinder
solely for Hilla class checks, reducing the number of scans performed during
the build.

Fixes #19616
Fixes #19009
Fixes #20385
mcollovati added a commit that referenced this issue Nov 20, 2024
Run Flow mojos using an isolated class loader that includes both project and
plugin dependencies, with project dependencies taking precedence. This ensures
that classes are always loaded from the same class loader at runtime, preventing
errors where a class might be loaded by the plugin's class loader while one of
its parent classes is only available in the project’s class loader (see #19616).

Additionally, this approach prevents the retrieval of resources from plugin
dependencies when the same artifact is defined within the project (see #19009).

This refactoring also introduces caching for ClassFinder instances per
execution phase, allowing multiple goals configured for the same phase to reuse
the same ClassFinder. It also removes the need to instantiate a ClassFinder
solely for Hilla class checks, reducing the number of scans performed during
the build.

Fixes #19616
Fixes #19009
Fixes #20385
mcollovati added a commit that referenced this issue Nov 20, 2024
Run Flow mojos using an isolated class loader that includes both project and
plugin dependencies, with project dependencies taking precedence. This ensures
that classes are always loaded from the same class loader at runtime, preventing
errors where a class might be loaded by the plugin's class loader while one of
its parent classes is only available in the project’s class loader (see #19616).

Additionally, this approach prevents the retrieval of resources from plugin
dependencies when the same artifact is defined within the project (see #19009).

This refactoring also introduces caching for ClassFinder instances per
execution phase, allowing multiple goals configured for the same phase to reuse
the same ClassFinder. It also removes the need to instantiate a ClassFinder
solely for Hilla class checks, reducing the number of scans performed during
the build.

Fixes #19616
Fixes #19009
Fixes #20385
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 24.4.18.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
4 participants