0

We have a monorepo where we have recently added the MAVEN_REPOS to be used with Bazel. We are using Quarkus 2.9.2.Final. So I am planning to create a CLI Application using Quarkus. But whenever I am running them I am getting a runtime exception. Following how my code looks like -

BUILD.bazel

load("@rules_java//java:defs.bzl", "java_binary", "java_library")
load("//build/bazel/rule_app_launcher:task_master.bzl", "tm_task")

java_binary(
    name = "MyApp",
    srcs = ["Main.java"],
    main_class = "<package to the Main class>.Main",
    resources = ["<references to the application properties>"],
    visibility = ["//visibility:public"],
    deps = [
        "@maven//:io_quarkus_quarkus_arc",
        "@maven//:io_quarkus_quarkus_core",
    ],
)

Main.java

import io.quarkus.runtime.Quarkus;
import io.quarkus.runtime.QuarkusApplication;
import io.quarkus.runtime.annotations.QuarkusMain;

@QuarkusMain
public class Main {

    public static void main(String... args) {
        Quarkus.run(HelloWorldMain.class, args);
    }


    public class HelloWorldMain implements QuarkusApplication {
        @Override
        public int run(String... args) throws Exception {
            System.out.println("Hello " + args[0]);
            return 0;
        }
    }

}

Following is the error I am getting when running bazel run //:MyApp

Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at io.quarkus.launcher.QuarkusLauncher.launch(QuarkusLauncher.java:58)
        at io.quarkus.runtime.Quarkus.launchFromIDE(Quarkus.java:97)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:84)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:41)
        at <package to the Main class>.Main.main(Main.java:12)
Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.quarkus.launcher.QuarkusLauncher.launch(QuarkusLauncher.java:56)
        ... 4 more
Caused by: java.lang.IllegalStateException: Failed to locate project dir for /home/User123/.cache/bazel/_bazel_User123/b0cc32ca6725cc3e1476fd4087bd3d1d/execroot/app/bazel-out/k8-fastbuild/bin/<component path>/MyApp.jar
        at io.quarkus.bootstrap.IDELauncherImpl.launch(IDELauncherImpl.java:38)
        ... 9 more

Appreciate for any clues to solve this problem.

Thanks.

Debopam Mitra
  • 1,842
  • 4
  • 27
  • 51
  • This is not going to work. Quarkus performs massive amount of work during application build, for which there is a Maven plugin and a Gradle plugin. Other ways of running a Quarkus application, such as for testing or dev mode or IDE launch, have special code paths that do the same. You'd need a Bazel plugin for Quarkus I'm afraid. – Ladicek May 27 '23 at 09:28
  • Thank you for this information. Will try out some other approaches. – Debopam Mitra Jun 01 '23 at 08:21

0 Answers0