org.gradle.api.tasks.diagnostics.DependencyInsightReportTask Maven / Gradle / Ivy
Show all versions of gradle-api Show documentation
/*
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.api.tasks.diagnostics;
import org.apache.commons.lang.StringUtils;
import org.gradle.api.Action;
import org.gradle.api.DefaultTask;
import org.gradle.api.Incubating;
import org.gradle.api.InvalidUserDataException;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.result.DependencyResult;
import org.gradle.api.artifacts.result.ResolutionResult;
import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionComparator;
import org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelectorScheme;
import org.gradle.api.internal.tasks.options.Option;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.diagnostics.internal.dsl.DependencyResultSpecNotationConverter;
import org.gradle.api.tasks.diagnostics.internal.graph.DependencyGraphRenderer;
import org.gradle.api.tasks.diagnostics.internal.graph.LegendRenderer;
import org.gradle.api.tasks.diagnostics.internal.graph.NodeRenderer;
import org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableDependency;
import org.gradle.api.tasks.diagnostics.internal.insight.DependencyInsightReporter;
import org.gradle.internal.graph.GraphRenderer;
import org.gradle.internal.logging.text.StyledTextOutput;
import org.gradle.internal.logging.text.StyledTextOutputFactory;
import org.gradle.internal.typeconversion.NotationParser;
import javax.inject.Inject;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
import static org.gradle.internal.logging.text.StyledTextOutput.Style.*;
/**
* Generates a report that attempts to answer questions like:
*
* - Why is this dependency in the dependency graph?
* - Exactly which dependencies are pulling this dependency into the graph?
* - What is the actual version (i.e. *selected* version) of the dependency that will be used? Is it the same as what was *requested*?
* - Why is the *selected* version of a dependency different to the *requested*?
*
*
* Use this task to get insight into a particular dependency (or dependencies)
* and find out what exactly happens during dependency resolution and conflict resolution.
* If the dependency version was forced or selected by the conflict resolution
* this information will be available in the report.
*
* While the regular dependencies report ({@link DependencyReportTask}) shows the path from the top level dependencies down through the transitive dependencies,
* the dependency insight report shows the path from a particular dependency to the dependencies that pulled it in.
* That is, it is an inverted view of the regular dependencies report.
*
* The task requires setting the dependency spec and the configuration.
* For more information on how to configure those please refer to docs for
* {@link DependencyInsightReportTask#setDependencySpec(Object)} and
* {@link DependencyInsightReportTask#setConfiguration(String)}.
*
* The task can also be configured from the command line.
* For more information please refer to {@link DependencyInsightReportTask#setDependencySpec(Object)}
* and {@link DependencyInsightReportTask#setConfiguration(String)}
*/
@Incubating
public class DependencyInsightReportTask extends DefaultTask {
private Configuration configuration;
private Spec dependencySpec;
/**
* Selects the dependency (or dependencies if multiple matches found) to show the report for.
*/
@Internal
public Spec getDependencySpec() {
return dependencySpec;
}
/**
* The dependency spec selects the dependency (or dependencies if multiple matches found) to show the report for. The spec receives an instance of {@link DependencyResult} as parameter.
*/
public void setDependencySpec(Spec dependencySpec) {
this.dependencySpec = dependencySpec;
}
/**
* Configures the dependency to show the report for.
* Multiple notation formats are supported: Strings, instances of {@link Spec}
* and groovy closures. Spec and closure receive {@link DependencyResult} as parameter.
* Examples of String notation: 'org.slf4j:slf4j-api', 'slf4j-api', or simply: 'slf4j'.
* The input may potentially match multiple dependencies.
* See also {@link DependencyInsightReportTask#setDependencySpec(Spec)}
*
* This method is exposed to the command line interface. Example usage:
*
gradle dependencyInsight --dependency slf4j
*/
@Option(option = "dependency", description = "Shows the details of given dependency.")
public void setDependencySpec(Object dependencyInsightNotation) {
NotationParser