downloadMavenSources static method

Future<void> downloadMavenSources(
  1. List<MavenDependency> deps,
  2. String targetDir
)

Downloads and unpacks source files of deps into targetDir.

Implementation

static Future<void> downloadMavenSources(
    List<MavenDependency> deps, String targetDir) async {
  for (var i = 0; i < deps.length; i++) {
    final sourceJarLocation = deps[i].toURLString(repoLocation);
    await File(join(targetDir, deps[i].filename()))
        .writeAsBytes(await http.readBytes(Uri.parse(sourceJarLocation)));
  }
  // Use gradle to extract the source jars.
  // This flow is needed because Gradle
  // defaults to compiled jars where available.
  final tempDir = await currentDir.createTemp('maven_temp_');
  await _runGradleCommand(deps, extractSources: true, targetDir);
  await tempDir.delete(recursive: true);
}