createVerifyDependenciesTask function

Task createVerifyDependenciesTask(
  1. JbFiles jbFiles,
  2. DepsCache depsCache,
  3. DartleCache cache
)

Implementation

Task createVerifyDependenciesTask(
  JbFiles jbFiles,
  DepsCache depsCache,
  DartleCache cache,
) {
  const link =
      'https://renatoathaydes.github.io/jb/pages/dependency-management.html';
  return Task(
    (List<String> _) async {
      final deps = await depsCache.send(GetDeps(jbFiles.dependenciesFile.path));
      final procDeps = await depsCache.send(
        GetDeps(jbFiles.processorDependenciesFile.path),
      );

      if (procDeps.warnings.isNotEmpty) {
        logger.warning(
          'Annotation Processor dependencies contains version conflicts',
        );
      }
      for (final (deps, forProcessor) in [(deps, false), (procDeps, true)]) {
        if (deps.warnings.isNotEmpty) {
          if (deps.warnings.isNotEmpty) {
            final prefix = forProcessor ? 'Annotation Processor' : 'Project';
            logger.warning('$prefix dependencies are problematic.');
          }
          printDepWarnings(deps);
          failBuild(
            reason:
                'Dependency graph contains version conflicts (see above)!\n'
                'You need to fix the conflicts as explained at $link',
          );
        }
      }
    },
    name: verifyDepsTaskName,
    runCondition: RunOnChanges(
      inputs: files([
        jbFiles.dependenciesFile.path,
        jbFiles.processorDependenciesFile.path,
      ]),
      cache: cache,
    ),
    dependsOn: {writeDepsTaskName},
    phase: depsPhase,
    description:
        'Fails the build if dependency version conflicts are detected.',
  );
}