use of org.gradle.api.artifacts.dsl.DependencyHandler in project gradle by gradle.
the class IdeaDependenciesProvider method visitDependencies.
private IdeaDependenciesVisitor visitDependencies(IdeaModule ideaModule, GeneratedIdeaScope scope) {
ProjectInternal projectInternal = (ProjectInternal) ideaModule.getProject();
final DependencyHandler handler = projectInternal.getDependencies();
final Collection<Configuration> plusConfigurations = getPlusConfigurations(ideaModule, scope);
final Collection<Configuration> minusConfigurations = getMinusConfigurations(ideaModule, scope);
final JavaModuleDetector javaModuleDetector = projectInternal.getServices().get(JavaModuleDetector.class);
final IdeaDependenciesVisitor visitor = new IdeaDependenciesVisitor(ideaModule, scope.name());
return projectInternal.getOwner().fromMutableState(p -> {
new IdeDependencySet(handler, javaModuleDetector, plusConfigurations, minusConfigurations, false, gradleApiSourcesResolver).visit(visitor);
return visitor;
});
}
use of org.gradle.api.artifacts.dsl.DependencyHandler in project gradle by gradle.
the class JavaGradlePluginPlugin method applyDependencies.
private void applyDependencies(Project project) {
DependencyHandler dependencies = project.getDependencies();
dependencies.add(API_CONFIGURATION, dependencies.gradleApi());
}
use of org.gradle.api.artifacts.dsl.DependencyHandler in project meecrowave by apache.
the class MeecrowavePlugin method apply.
@Override
public void apply(final Project project) {
project.getExtensions().create(NAME, MeecrowaveExtension.class);
project.afterEvaluate(actionProject -> {
final MeecrowaveExtension extension = MeecrowaveExtension.class.cast(actionProject.getExtensions().findByName(NAME));
if (extension != null && extension.isSkipMavenCentral()) {
return;
}
actionProject.getRepositories().mavenCentral();
});
final Configuration configuration = project.getConfigurations().maybeCreate(NAME);
configuration.getIncoming().beforeResolve(resolvableDependencies -> {
String version;
try {
final String resource = "META-INF/maven/org.apache.meecrowave/meecrowave-gradle-plugin/pom.properties";
try (final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)) {
final Properties p = new Properties();
p.load(is);
version = p.getProperty("version");
}
} catch (final IOException e) {
throw new IllegalStateException(e);
}
final DependencyHandler dependencyHandler = project.getDependencies();
final DependencySet dependencies = configuration.getDependencies();
dependencies.add(dependencyHandler.create("org.apache.meecrowave:meecrowave-core:" + version));
});
project.task(new HashMap<String, Object>() {
{
put("type", MeecrowaveTask.class);
put("group", "Embedded Application Server");
put("description", "Starts a meecrowave!");
}
}, NAME);
}
use of org.gradle.api.artifacts.dsl.DependencyHandler 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));
});
}
use of org.gradle.api.artifacts.dsl.DependencyHandler in project gradle by gradle.
the class JavaTestFixturesPlugin method createImplicitTestFixturesDependencies.
private void createImplicitTestFixturesDependencies(Project project, JavaPluginExtension extension) {
DependencyHandler dependencies = project.getDependencies();
dependencies.add(TEST_FIXTURES_API, dependencies.create(project));
SourceSet testSourceSet = findTestSourceSet(extension);
ProjectDependency testDependency = (ProjectDependency) dependencies.add(testSourceSet.getImplementationConfigurationName(), dependencies.create(project));
testDependency.capabilities(new ProjectTestFixtures(project));
// Overwrite what the Java plugin defines for test, in order to avoid duplicate classes
// see gradle/gradle#10872
ConfigurationContainer configurations = project.getConfigurations();
testSourceSet.setCompileClasspath(project.getObjects().fileCollection().from(configurations.getByName(TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME)));
testSourceSet.setRuntimeClasspath(project.getObjects().fileCollection().from(testSourceSet.getOutput(), configurations.getByName(TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME)));
}
Aggregations