quarkiverse / quarkus-web-bundler

Create full-stack web apps quickly and easily with this Quarkus extension. It offers zero-configuration bundling for your web app scripts (JS, JSX, TS, TSX), dependencies (jQuery, React, htmx, etc.), and styles (CSS, SCSS, SASS).
Apache License 2.0
18 stars 10 forks source link

[Do Not Merge] Multi-module hack for projects that reference a parent. #46

Closed chrisruffalo closed 1 year ago

chrisruffalo commented 1 year ago

This is a fix I had to use for getting around an issue with the way that the buildDir was being calculated/found in multi-module projects.

My project is structured like this:

When building the frontend module (either from the parent or from within the frontend directory) I get the following error:

[ERROR] Failed to execute goal io.quarkus:quarkus-maven-plugin:3.2.0.Final:build (default-quarkus) on project koino-service-auth: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR]         [error]: Build step io.quarkiverse.web.bundler.deployment.staticresources.GeneratedStaticResourcesProcessor#processStaticFiles threw an exception: java.lang.NullPointerException: Cannot invoke "io.quarkus.bootstrap.workspace.WorkspaceModule.getBuildDir()" because the return value of "io.quarkus.maven.dependency.ResolvedDependency.getWorkspaceModule()" is null
[ERROR]         at io.quarkiverse.web.bundler.deployment.staticresources.GeneratedStaticResourcesProcessor.getBuildDirectory(GeneratedStaticResourcesProcessor.java:110)
[ERROR]         at io.quarkiverse.web.bundler.deployment.staticresources.GeneratedStaticResourcesProcessor.processStaticFiles(GeneratedStaticResourcesProcessor.java:38)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[ERROR]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]         at java.base/java.lang.reflect.Method.invoke(Method.java:568)
[ERROR]         at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:909)
[ERROR]         at io.quarkus.builder.BuildContext.run(BuildContext.java:282)
[ERROR]         at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
[ERROR]         at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
[ERROR]         at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
[ERROR]         at java.base/java.lang.Thread.run(Thread.java:833)
[ERROR]         at org.jboss.threads.JBossThread.run(JBossThread.java:501)
[ERROR] -> [Help 1]

This lead me to make the change in this PR and then set up the quarkus-maven-plugin:

<plugin>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>default-quarkus</id>
            <configuration>
                <systemProperties>
                    <quarkus.web.bundler.buildDir>${project.build.directory}</quarkus.web.bundler.buildDir>
                </systemProperties>
            </configuration>
        </execution>
    </executions>
</plugin>

This fixes the problem but clearly isn't the way it should be done.

ia3andy commented 1 year ago

Stupid question, why do you separate frontend and backend?

ia3andy commented 1 year ago

@aloubyansky shouldn't we handle this at Quarkus core level (have a look at the PR code)

aloubyansky commented 1 year ago

How could we reproduce the issue @chrisruffalo?

chrisruffalo commented 1 year ago

Oh, sorry, frontend and backend were just for illustrative purposes. They're really microservices that share the same SSO but handle different aspects of the application. (One is the frontend/backend, one is API-only for scaling purposes. My personal project is all silly so it doesn't necessarily make sense anyway.)

Speaking for the other project there are four microservices and only one has a UI, even if I only enable the web bundler in one submodule it doesn't work.

@aloubyansky to reproduce it I can just make a multi-module project I can share. I need to work on that. And @ia3andy I figured this would require a Quarkus-level solution but I had hoped I was just missing some injection.

aloubyansky commented 1 year ago

@chrisruffalo a reproducer would help

chrisruffalo commented 1 year ago

Minimal-est reproducer, it doesn't even take more than one module to make it break: https://github.com/chrisruffalo/web-bundler-reproducer. Thanks!

aloubyansky commented 1 year ago

Thanks @chrisruffalo A quick workaround for you would be to enable quarkus.bootstrap.workspace-discovery, which is disabled for the build goal.

aloubyansky commented 1 year ago

It looks like the logic that involves static resource cleaning is meant to be executed only in dev and test modes, in those modes workspace discovery is enabled by default and the build directory will be available. Based on that, here is an alternative https://github.com/quarkiverse/quarkus-web-bundler/pull/49

chrisruffalo commented 1 year ago

@aloubyansky that tracks, I forgot to mention everything works fine in dev mode. Thanks!

ia3andy commented 1 year ago

I'll release soon!

ia3andy commented 4 months ago

@all-contributors please add @chrisruffalo for code

allcontributors[bot] commented 4 months ago

@ia3andy

I've put up a pull request to add @chrisruffalo! :tada: