javamavenquarkus

How to read dependencies in Quarkus (maven)


I have a library, which a service can import. Among other things, this library is supposed to run a check if a quarkus-info dependency is installed on the service that is using the library.

How could I understand if a quarkus-info dependency is installed at runtime? One of the ideas I had is to run mvn quarkus:dependency-tree and read through each line if it contains "quarkus-info". Manually in cmd I can do it just fine. However, with Java code that fails -

ProcessBuilder processBuilder = new ProcessBuilder("mvn", "quarkus:dependency-tree");
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();

results in

Cannot run program "mvn": CreateProcess error=2, The system cannot find the file specified


Solution

  • You need to do something like the following:

    public static void hasQuarkusInfo() {
       try {
          Class.forName("io.quarkus.info.BuildInfo", false, Thread.currentThread().getContextClassLoader());
       } catch(ClassNotFoundException ignored) {
          return false;
       }  
    }