private Collection loadArtifactsAndCheckConflicts()

in maven-plugin/src/main/java/com/spotify/missinglink/maven/CheckMojo.java [414:480]


  private Collection<Conflict> loadArtifactsAndCheckConflicts() {
    // includes declared and transitive dependencies, anything in the scopes configured to be
    // included
    final List<org.apache.maven.artifact.Artifact> projectDeps =
        this.project.getArtifacts().stream()
            .filter(artifact -> includeScopes.contains(Scope.valueOf(artifact.getScope())))
            .collect(Collectors.toList());

    getLog()
        .debug(
            "project dependencies: "
                + projectDeps.stream().map(this::mavenCoordinates).collect(Collectors.toList()));

    Stopwatch stopwatch = Stopwatch.createStarted();
    // artifacts in runtime scope from the maven project (including transitives)
    final ImmutableList<Artifact> runtimeProjectArtifacts = constructArtifacts(projectDeps);
    stopwatch.stop();
    getLog().debug("constructing runtime artifacts took: " + asMillis(stopwatch) + " ms");

    // also need to load JDK classes from the bootstrap classpath
    final String bootstrapClasspath = bootClassPathToUse();

    stopwatch.reset().start();

    final List<Artifact> bootstrapArtifacts = loadBootstrapArtifacts(bootstrapClasspath);

    stopwatch.stop();
    getLog().debug("constructing bootstrap artifacts took: " + asMillis(stopwatch) + " ms");

    final ImmutableList<Artifact> allArtifacts =
        ImmutableList.<Artifact>builder()
            .addAll(runtimeProjectArtifacts)
            .addAll(bootstrapArtifacts)
            .build();

    final ImmutableList<Artifact> runtimeArtifactsAfterExclusions =
        ImmutableList.copyOf(
            runtimeProjectArtifacts.stream()
                .filter(artifact -> !isExcluded(artifact))
                .collect(Collectors.toSet()));

    final Artifact projectArtifact = toArtifact(project.getBuild().getOutputDirectory());

    if (projectArtifact.classes().isEmpty()) {
      getLog()
          .warn(
              "No classes found in project build directory"
                  + " - did you run 'mvn compile' first?");
    }

    stopwatch.reset().start();

    getLog().debug("Checking for conflicts starting from " + projectArtifact.name().name());
    getLog().debug("Artifacts included in the project: ");
    for (Artifact artifact : runtimeArtifactsAfterExclusions) {
      getLog().debug("    " + artifact.name().name());
    }

    final Collection<Conflict> conflicts =
        conflictChecker.check(projectArtifact, runtimeArtifactsAfterExclusions, allArtifacts);

    stopwatch.stop();
    getLog().debug("conflict checking took: " + asMillis(stopwatch) + " ms");

    getLog().debug(conflicts.size() + " total conflicts found");
    return conflicts;
  }