Search in sources :

Example 6 with DependencyHandler

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;
    });
}
Also used : IdeDependencySet(org.gradle.plugins.ide.internal.resolver.IdeDependencySet) UnresolvedIdeDependencyHandler(org.gradle.plugins.ide.internal.resolver.UnresolvedIdeDependencyHandler) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) Configuration(org.gradle.api.artifacts.Configuration) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) JavaModuleDetector(org.gradle.internal.jvm.JavaModuleDetector)

Example 7 with DependencyHandler

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());
}
Also used : DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler)

Example 8 with DependencyHandler

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);
}
Also used : DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) Configuration(org.gradle.api.artifacts.Configuration) InputStream(java.io.InputStream) DependencySet(org.gradle.api.artifacts.DependencySet) IOException(java.io.IOException) Properties(java.util.Properties)

Example 9 with DependencyHandler

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));
    });
}
Also used : ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) BiFunction(java.util.function.BiFunction) InvalidUserCodeException(org.gradle.api.InvalidUserCodeException) Task(org.gradle.api.Task) Provider(org.gradle.api.provider.Provider) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) MultipleCandidatesDetails(org.gradle.api.attributes.MultipleCandidatesDetails) TaskProvider(org.gradle.api.tasks.TaskProvider) Log4jBannedVersion(org.gradle.internal.logging.util.Log4jBannedVersion) ConfigurationInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationInternal) ExtensionAware(org.gradle.api.plugins.ExtensionAware) Transformer(org.gradle.api.Transformer) ScalaRuntime(org.gradle.api.tasks.ScalaRuntime) CompileOptions(org.gradle.api.tasks.compile.CompileOptions) DefaultScalaPluginExtension(org.gradle.api.internal.tasks.scala.DefaultScalaPluginExtension) ImmutableSet(com.google.common.collect.ImmutableSet) Project(org.gradle.api.Project) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) ArtifactView(org.gradle.api.artifacts.ArtifactView) JvmEcosystemUtilities(org.gradle.api.plugins.jvm.internal.JvmEcosystemUtilities) AttributeDisambiguationRule(org.gradle.api.attributes.AttributeDisambiguationRule) Spec(org.gradle.api.specs.Spec) AttributeMatchingStrategy(org.gradle.api.attributes.AttributeMatchingStrategy) SerializableLambdas.spec(org.gradle.api.internal.lambdas.SerializableLambdas.spec) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) JavaToolchainService(org.gradle.jvm.toolchain.JavaToolchainService) Callable(java.util.concurrent.Callable) FileCollection(org.gradle.api.file.FileCollection) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) SourceSet(org.gradle.api.tasks.SourceSet) Inject(javax.inject.Inject) Configuration(org.gradle.api.artifacts.Configuration) ScalaDoc(org.gradle.api.tasks.scala.ScalaDoc) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) ScalaSourceDirectorySet(org.gradle.api.tasks.ScalaSourceDirectorySet) ScalaCompile(org.gradle.api.tasks.scala.ScalaCompile) Usage(org.gradle.api.attributes.Usage) InvokerHelper(org.codehaus.groovy.runtime.InvokerHelper) Action(org.gradle.api.Action) ReportingExtension(org.gradle.api.reporting.ReportingExtension) Jar(org.gradle.jvm.tasks.Jar) JvmPluginsHelper(org.gradle.api.plugins.internal.JvmPluginsHelper) JavaToolchainSpec(org.gradle.jvm.toolchain.JavaToolchainSpec) File(java.io.File) USAGE_ATTRIBUTE(org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE) ObjectFactory(org.gradle.api.model.ObjectFactory) Convention(org.gradle.api.plugins.Convention) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Plugin(org.gradle.api.Plugin) IncrementalCompileOptions(org.gradle.api.tasks.scala.IncrementalCompileOptions) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) Usage(org.gradle.api.attributes.Usage) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) Configuration(org.gradle.api.artifacts.Configuration) InvalidUserCodeException(org.gradle.api.InvalidUserCodeException) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) ConfigurationInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationInternal)

Example 10 with DependencyHandler

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)));
}
Also used : DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) SourceSet(org.gradle.api.tasks.SourceSet) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) ProjectTestFixtures(org.gradle.internal.component.external.model.ProjectTestFixtures)

Aggregations

DependencyHandler (org.gradle.api.artifacts.dsl.DependencyHandler)18 Configuration (org.gradle.api.artifacts.Configuration)12 Project (org.gradle.api.Project)7 File (java.io.File)6 EtaConfiguration (com.typelead.gradle.eta.api.EtaConfiguration)3 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)3 DependencySet (org.gradle.api.artifacts.DependencySet)3 Usage (org.gradle.api.attributes.Usage)3 FileCollection (org.gradle.api.file.FileCollection)3 AndroidArtifacts (com.android.build.gradle.internal.publishing.AndroidArtifacts)2 AtlasAndroidArtifacts (com.android.build.gradle.internal.publishing.AtlasAndroidArtifacts)2 EtlasCommand (com.typelead.gradle.utils.EtlasCommand)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Properties (java.util.Properties)2 Callable (java.util.concurrent.Callable)2 Action (org.gradle.api.Action)2 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)2 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)2 AttributeContainer (org.gradle.api.attributes.AttributeContainer)2