code: private void shutdownIfComplete() {
          // only shut down if you have updated build results AND profile information
          if (!buildProfileComplete.get() || !buildResultComplete.get()) {
              return;
          }
  
          MetricsDispatcher dispatcher = this.dispatcherSupplier.get();
          logger.info("Shutting down dispatcher");
          try {
              dispatcher.stopAsync().awaitTerminated(TIMEOUT_MS, TimeUnit.MILLISECONDS);
          } catch (TimeoutException e) {
              logger.debug("Timed out after {}ms while waiting for metrics dispatcher to terminate", TIMEOUT_MS);
          } catch (IllegalStateException e) {
              logger.debug("Could not stop metrics dispatcher service (error message: {})", getRootCauseMessage(e));
          }
  
          Optional<String> receipt = dispatcher.receipt();
          if (receipt.isPresent()) {
              logger.warn(receipt.get());
          }
      }
docs: Conditionally shutdown the dispatcher, because Gradle listener event order appears to be non-deterministic.