use of org.gradle.api.artifacts.Dependency in project spring-boot by spring-projects.
the class CheckClasspathForUnnecessaryExclusions method checkForUnnecessaryExclusions.
@TaskAction
public void checkForUnnecessaryExclusions() {
Map<String, Set<String>> unnecessaryExclusions = new HashMap<>();
this.exclusionsByDependencyId.forEach((dependencyId, exclusions) -> {
if (!exclusions.isEmpty()) {
Dependency toCheck = this.dependencyById.get(dependencyId);
List<String> dependencies = this.configurations.detachedConfiguration(toCheck, this.platform).getIncoming().getArtifacts().getArtifacts().stream().map(this::getId).collect(Collectors.toList());
exclusions.removeAll(dependencies);
removeProfileExclusions(dependencyId, exclusions);
if (!exclusions.isEmpty()) {
unnecessaryExclusions.put(dependencyId, exclusions);
}
}
});
if (!unnecessaryExclusions.isEmpty()) {
throw new GradleException(getExceptionMessage(unnecessaryExclusions));
}
}
use of org.gradle.api.artifacts.Dependency in project gradle by gradle.
the class GroovyRuntime method inferGroovyClasspath.
/**
* Searches the specified class path for Groovy Jars ({@code groovy(-indy)}, {@code groovy-all(-indy)}) and returns a corresponding class path for executing Groovy tools such as the Groovy
* compiler and Groovydoc tool. The tool versions will match those of the Groovy Jars found. If no Groovy Jars are found on the specified class path, a class path with the contents of the {@code
* groovy} configuration will be returned.
*
* <p>The returned class path may be empty, or may fail to resolve when asked for its contents.
*
* @param classpath a class path containing Groovy Jars
* @return a corresponding class path for executing Groovy tools such as the Groovy compiler and Groovydoc tool
*/
public FileCollection inferGroovyClasspath(final Iterable<File> classpath) {
// would differ in at least the following ways: 1. live 2. no autowiring
return new LazilyInitializedFileCollection() {
@Override
public String getDisplayName() {
return "Groovy runtime classpath";
}
@Override
public FileCollection createDelegate() {
try {
return inferGroovyClasspath();
} catch (RuntimeException e) {
return new FailingFileCollection(getDisplayName(), e);
}
}
private FileCollection inferGroovyClasspath() {
GroovyJarFile groovyJar = findGroovyJarFile(classpath);
if (groovyJar == null) {
throw new GradleException(String.format("Cannot infer Groovy class path because no Groovy Jar was found on class path: %s", Iterables.toString(classpath)));
}
if (groovyJar.isGroovyAll()) {
return project.getLayout().files(groovyJar.getFile());
}
VersionNumber groovyVersion = groovyJar.getVersion();
// Groovy 3 does not have groovy-all yet we may have the required pieces on classpath via localGroovy()
if (groovyVersion.getMajor() == 3) {
return inferGroovy3Classpath(groovyVersion);
}
String notation = groovyJar.getDependencyNotation();
List<Dependency> dependencies = new ArrayList<>();
addDependencyTo(dependencies, notation);
if (groovyVersion.compareTo(GROOVY_VERSION_WITH_SEPARATE_ANT) >= 0) {
// add groovy-ant to bring in Groovydoc for Groovy 2.0+
addGroovyDependency(notation, dependencies, "groovy-ant");
}
if (groovyVersion.compareTo(GROOVY_VERSION_REQUIRING_TEMPLATES) >= 0) {
// add groovy-templates for Groovy 2.5+
addGroovyDependency(notation, dependencies, "groovy-templates");
}
return detachedRuntimeClasspath(dependencies.toArray(new Dependency[0]));
}
private void addGroovyDependency(String groovyDependencyNotion, List<Dependency> dependencies, String otherDependency) {
String notation = groovyDependencyNotion.replace(":groovy:", ":" + otherDependency + ":");
addDependencyTo(dependencies, notation);
}
private void addDependencyTo(List<Dependency> dependencies, String notation) {
// project.getDependencies().create(String) seems to be the only feasible way to create a Dependency with a classifier
dependencies.add(project.getDependencies().create(notation));
}
private FileCollection inferGroovy3Classpath(VersionNumber groovyVersion) {
Set<String> groovyJarNames = groovyJarNamesFor(groovyVersion);
List<File> groovyClasspath = collectJarsFromClasspath(classpath, groovyJarNames);
if (groovyClasspath.size() == GROOVY3_LIBS.size()) {
return project.getLayout().files(groovyClasspath);
}
return detachedRuntimeClasspath(GROOVY3_LIBS.stream().map(libName -> project.getDependencies().create("org.codehaus.groovy:" + libName + ":" + groovyVersion)).toArray(Dependency[]::new));
}
private Configuration detachedRuntimeClasspath(Dependency... dependencies) {
Configuration classpath = project.getConfigurations().detachedConfiguration(dependencies);
jvmEcosystemUtilities().configureAsRuntimeClasspath(classpath);
return classpath;
}
// let's override this so that delegate isn't created at autowiring time (which would mean on every build)
@Override
public void visitDependencies(TaskDependencyResolveContext context) {
if (classpath instanceof Buildable) {
context.add(classpath);
}
}
};
}
use of org.gradle.api.artifacts.Dependency in project gradle by gradle.
the class DefaultAutoAppliedPluginHandler method isAlreadyRequestedInBuildScriptBlock.
private static boolean isAlreadyRequestedInBuildScriptBlock(PluginRequestInternal autoAppliedPlugin, ScriptHandler scriptHandler) {
ModuleVersionSelector module = autoAppliedPlugin.getModule();
if (module == null) {
return false;
}
Configuration classpathConfiguration = scriptHandler.getConfigurations().getByName(ScriptHandler.CLASSPATH_CONFIGURATION);
for (Dependency dependency : classpathConfiguration.getDependencies()) {
if (module.getGroup().equals(dependency.getGroup()) && module.getName().equals(dependency.getName())) {
return true;
}
}
return false;
}
use of org.gradle.api.artifacts.Dependency in project gradle by gradle.
the class DefaultDependencyFactory method createDependency.
@Override
public Dependency createDependency(Object dependencyNotation) {
Dependency dependency = dependencyNotationParser.parseNotation(dependencyNotation);
injectServices(dependency);
return dependency;
}
use of org.gradle.api.artifacts.Dependency in project gradle by gradle.
the class DefaultDependencyHandler method platform.
@Override
public Dependency platform(Object notation, Action<? super Dependency> configureAction) {
Dependency dep = platform(notation);
configureAction.execute(dep);
return dep;
}
Aggregations