description = "[ groupId :artifactId {:version :scope :packaging} ]",
help = "managed dependency identifier, ex: \"org.jboss.forge:forge-api:1.0.0\"") Dependency gav,
final PipeOut out
)
{
DependencyFacet manDeps = project.getFacet(DependencyFacet.class);
if (!manDeps.hasEffectiveManagedDependency(gav)
|| shell.promptBoolean(
"Managed dependency already exists [" + gav.getGroupId() + ":" + gav.getArtifactId()
+ "], continue?", true))
{
DependencyBuilder search = DependencyBuilder.create(gav).setVersion("[0,)");
List<Dependency> availableVersions = manDeps.resolveAvailableVersions(search);
if (availableVersions.isEmpty())
{
throw new RuntimeException("No available versions resolved for managed dependency [" + gav + "]");
}
if (!availableVersions.contains(gav))
{
ShellMessages.info(out, "No artifact found for managed dependency [" + gav + "]");
if (availableVersions.size() > 1)
{
gav = shell.promptChoiceTyped("Add which version?", availableVersions);
}
else if (shell.promptBoolean("Use [" + availableVersions.get(0) + "] instead?", true))
{
gav = availableVersions.get(0);
}
else
{
throw new RuntimeException("Could not add managed dependency [" + gav + "]");
}
}
if (manDeps.hasEffectiveManagedDependency(gav))
{
Dependency managedDependency = manDeps.getManagedDependency(gav);
manDeps.removeManagedDependency(managedDependency);
}
manDeps.addManagedDependency(gav);
out.println("Added managed dependency [" + gav + "]");
}
else
{
ShellMessages.info(out, "Aborted.");