use of org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE in project gradle by gradle.
the class ScalaBasePlugin method configureConfigurations.
private void configureConfigurations(final Project project, final Usage incrementalAnalysisUsage, ScalaPluginExtension scalaPluginExtension) {
DependencyHandler dependencyHandler = project.getDependencies();
ConfigurationInternal plugins = (ConfigurationInternal) project.getConfigurations().create(SCALA_COMPILER_PLUGINS_CONFIGURATION_NAME);
plugins.setTransitive(false);
plugins.setCanBeConsumed(false);
jvmEcosystemUtilities.configureAsRuntimeClasspath(plugins);
Configuration zinc = project.getConfigurations().create(ZINC_CONFIGURATION_NAME);
zinc.setVisible(false);
zinc.setDescription("The Zinc incremental compiler to be used for this Scala project.");
((DeprecatableConfiguration) zinc).deprecateForConsumption(deprecation -> deprecation.willBecomeAnErrorInGradle8().withUpgradeGuideSection(7, "plugin_configuration_consumption"));
zinc.getResolutionStrategy().eachDependency(rule -> {
if (rule.getRequested().getGroup().equals("com.typesafe.zinc") && rule.getRequested().getName().equals("zinc")) {
rule.useTarget("org.scala-sbt:zinc_" + DEFAULT_SCALA_ZINC_VERSION + ":" + DEFAULT_ZINC_VERSION);
rule.because("Typesafe Zinc is no longer maintained.");
}
});
zinc.defaultDependencies(dependencies -> {
dependencies.add(dependencyHandler.create("org.scala-sbt:zinc_" + DEFAULT_SCALA_ZINC_VERSION + ":" + scalaPluginExtension.getZincVersion().get()));
// Add safeguard and clear error if the user changed the scala version when using default zinc
zinc.getIncoming().afterResolve(resolvableDependencies -> {
resolvableDependencies.getResolutionResult().allComponents(component -> {
if (component.getModuleVersion() != null && component.getModuleVersion().getName().equals("scala-library")) {
if (!component.getModuleVersion().getVersion().startsWith(DEFAULT_SCALA_ZINC_VERSION)) {
throw new InvalidUserCodeException("The version of 'scala-library' was changed while using the default Zinc version. " + "Version " + component.getModuleVersion().getVersion() + " is not compatible with org.scala-sbt:zinc_" + DEFAULT_SCALA_ZINC_VERSION + ":" + DEFAULT_ZINC_VERSION);
}
}
});
});
});
zinc.getDependencyConstraints().add(dependencyHandler.getConstraints().create(Log4jBannedVersion.LOG4J2_CORE_COORDINATES, constraint -> constraint.version(version -> {
version.require(Log4jBannedVersion.LOG4J2_CORE_REQUIRED_VERSION);
version.reject(Log4jBannedVersion.LOG4J2_CORE_VULNERABLE_VERSION_RANGE);
})));
final Configuration incrementalAnalysisElements = project.getConfigurations().create("incrementalScalaAnalysisElements");
incrementalAnalysisElements.setVisible(false);
incrementalAnalysisElements.setDescription("Incremental compilation analysis files");
incrementalAnalysisElements.setCanBeResolved(false);
incrementalAnalysisElements.setCanBeConsumed(true);
incrementalAnalysisElements.getAttributes().attribute(USAGE_ATTRIBUTE, incrementalAnalysisUsage);
AttributeMatchingStrategy<Usage> matchingStrategy = dependencyHandler.getAttributesSchema().attribute(USAGE_ATTRIBUTE);
matchingStrategy.getDisambiguationRules().add(UsageDisambiguationRules.class, actionConfiguration -> {
actionConfiguration.params(incrementalAnalysisUsage);
actionConfiguration.params(objectFactory.named(Usage.class, Usage.JAVA_API));
actionConfiguration.params(objectFactory.named(Usage.class, Usage.JAVA_RUNTIME));
});
}
Aggregations