Search in sources :

Example 11 with Configuration

use of org.gradle.api.artifacts.Configuration in project gradle by gradle.

the class ArtifactRepositoryPluginResolver method exists.

/*
     * Checks whether the implementation artifact exists in the backing artifact repository.
     */
private boolean exists(PluginRequestInternal request) {
    Dependency dependency = resolution.getDependencyHandler().create(getMarkerDependency(request));
    ConfigurationContainer configurations = resolution.getConfigurationContainer();
    Configuration configuration = configurations.detachedConfiguration(dependency);
    configuration.setTransitive(false);
    return !configuration.getResolvedConfiguration().hasError();
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) DefaultExternalModuleDependency(org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency) Dependency(org.gradle.api.artifacts.Dependency)

Example 12 with Configuration

use of org.gradle.api.artifacts.Configuration in project gradle by gradle.

the class WarPlugin method apply.

public void apply(final Project project) {
    project.getPluginManager().apply(JavaPlugin.class);
    final WarPluginConvention pluginConvention = new WarPluginConvention(project);
    project.getConvention().getPlugins().put("war", pluginConvention);
    project.getTasks().withType(War.class, new Action<War>() {

        public void execute(War task) {
            task.from(new Callable() {

                public Object call() throws Exception {
                    return pluginConvention.getWebAppDir();
                }
            });
            task.dependsOn(new Callable() {

                public Object call() throws Exception {
                    return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
                }
            });
            task.classpath(new Object[] { new Callable() {

                public Object call() throws Exception {
                    FileCollection runtimeClasspath = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
                    Configuration providedRuntime = project.getConfigurations().getByName(PROVIDED_RUNTIME_CONFIGURATION_NAME);
                    return runtimeClasspath.minus(providedRuntime);
                }
            } });
        }
    });
    War war = project.getTasks().create(WAR_TASK_NAME, War.class);
    war.setDescription("Generates a war archive with all the compiled classes, the web-app content and the libraries.");
    war.setGroup(BasePlugin.BUILD_GROUP);
    ArchivePublishArtifact warArtifact = new ArchivePublishArtifact(war);
    project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(warArtifact);
    configureConfigurations(project.getConfigurations());
    configureComponent(project, warArtifact);
}
Also used : DefaultArtifactPublicationSet(org.gradle.api.internal.plugins.DefaultArtifactPublicationSet) Configuration(org.gradle.api.artifacts.Configuration) ArchivePublishArtifact(org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact) War(org.gradle.api.tasks.bundling.War) FileCollection(org.gradle.api.file.FileCollection) Callable(java.util.concurrent.Callable)

Example 13 with Configuration

use of org.gradle.api.artifacts.Configuration in project gradle by gradle.

the class JavaLibraryPlugin method addApiToMainSourceSet.

private void addApiToMainSourceSet(JavaPluginConvention convention, ConfigurationContainer configurations) {
    SourceSet sourceSet = convention.getSourceSets().getByName("main");
    Configuration apiConfiguration = configurations.maybeCreate(sourceSet.getApiConfigurationName());
    apiConfiguration.setVisible(false);
    apiConfiguration.setDescription("API dependencies for " + sourceSet + ".");
    apiConfiguration.setCanBeResolved(false);
    apiConfiguration.setCanBeConsumed(false);
    Configuration apiElementsConfiguration = configurations.getByName(sourceSet.getApiElementsConfigurationName());
    apiElementsConfiguration.extendsFrom(apiConfiguration);
    // Use a magic type to move the Jar variants out of the way so that the classes variant is used instead
    apiElementsConfiguration.getOutgoing().getAttributes().attribute(ArtifactAttributes.ARTIFACT_FORMAT, JavaPlugin.NON_DEFAULT_JAR_TYPE);
    Configuration implementationConfiguration = configurations.getByName(sourceSet.getImplementationConfigurationName());
    implementationConfiguration.extendsFrom(apiConfiguration);
    Configuration compileConfiguration = configurations.getByName(sourceSet.getCompileConfigurationName());
    apiConfiguration.extendsFrom(compileConfiguration);
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) Configuration(org.gradle.api.artifacts.Configuration)

Example 14 with Configuration

use of org.gradle.api.artifacts.Configuration in project gradle by gradle.

the class BasePlugin method configureConfigurations.

private void configureConfigurations(final Project project) {
    ConfigurationContainer configurations = project.getConfigurations();
    project.setStatus("integration");
    Configuration archivesConfiguration = configurations.maybeCreate(Dependency.ARCHIVES_CONFIGURATION).setDescription("Configuration for archive artifacts.");
    configurations.maybeCreate(Dependency.DEFAULT_CONFIGURATION).setDescription("Configuration for default artifacts.");
    final DefaultArtifactPublicationSet defaultArtifacts = project.getExtensions().create("defaultArtifacts", DefaultArtifactPublicationSet.class, archivesConfiguration.getArtifacts());
    configurations.all(new Action<Configuration>() {

        public void execute(Configuration configuration) {
            configuration.getArtifacts().all(new Action<PublishArtifact>() {

                public void execute(PublishArtifact artifact) {
                    defaultArtifacts.addCandidate(artifact);
                }
            });
        }
    });
}
Also used : Action(org.gradle.api.Action) DefaultArtifactPublicationSet(org.gradle.api.internal.plugins.DefaultArtifactPublicationSet) Configuration(org.gradle.api.artifacts.Configuration) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) PublishArtifact(org.gradle.api.artifacts.PublishArtifact)

Example 15 with Configuration

use of org.gradle.api.artifacts.Configuration in project gradle by gradle.

the class DefaultConfiguration method extendsFrom.

public Configuration extendsFrom(Configuration... extendsFrom) {
    validateMutation(MutationType.DEPENDENCIES);
    for (Configuration configuration : extendsFrom) {
        if (configuration.getHierarchy().contains(this)) {
            throw new InvalidUserDataException(String.format("Cyclic extendsFrom from %s and %s is not allowed. See existing hierarchy: %s", this, configuration, configuration.getHierarchy()));
        }
        if (this.extendsFrom.add(configuration)) {
            inheritedArtifacts.addCollection(configuration.getAllArtifacts());
            inheritedDependencies.addCollection(configuration.getAllDependencies());
            ((ConfigurationInternal) configuration).addMutationValidator(parentMutationValidator);
        }
    }
    return this;
}
Also used : ResolvedProjectConfiguration(org.gradle.api.internal.artifacts.ivyservice.resolveengine.projectresult.ResolvedProjectConfiguration) Configuration(org.gradle.api.artifacts.Configuration) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) InvalidUserDataException(org.gradle.api.InvalidUserDataException)

Aggregations

Configuration (org.gradle.api.artifacts.Configuration)85 Project (org.gradle.api.Project)11 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)11 File (java.io.File)10 Dependency (org.gradle.api.artifacts.Dependency)10 Callable (java.util.concurrent.Callable)9 ResolvedConfiguration (org.gradle.api.artifacts.ResolvedConfiguration)9 ResolvedProjectConfiguration (org.gradle.api.internal.artifacts.ivyservice.resolveengine.projectresult.ResolvedProjectConfiguration)9 DependencySet (org.gradle.api.artifacts.DependencySet)8 DefaultLenientConfiguration (org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration)7 LinkedHashSet (java.util.LinkedHashSet)6 Usage (org.gradle.api.attributes.Usage)6 Action (org.gradle.api.Action)5 ConventionMapping (org.gradle.api.internal.ConventionMapping)5 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)4 IConventionAware (org.gradle.api.internal.IConventionAware)4 ArchivePublishArtifact (org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact)4 DefaultUsageContext (org.gradle.language.cpp.internal.DefaultUsageContext)4 Set (java.util.Set)3 FileCollectionDependency (org.gradle.api.artifacts.FileCollectionDependency)3