Search in sources :

Example 6 with AttributeContainer

use of org.gradle.api.attributes.AttributeContainer in project native-build-tools by graalvm.

the class NativeImagePlugin method createNativeConfigurations.

@SuppressWarnings("unchecked")
private static NativeConfigurations createNativeConfigurations(Project project, String binaryName, String baseClasspathConfigurationName) {
    ConfigurationContainer configurations = project.getConfigurations();
    String prefix = "main".equals(binaryName) ? "" : capitalize(binaryName);
    Configuration baseClasspath = configurations.getByName(baseClasspathConfigurationName);
    Configuration compileOnly = configurations.create("nativeImage" + prefix + "CompileOnly", c -> {
        c.setCanBeResolved(false);
        c.setCanBeConsumed(false);
    });
    Configuration classpath = configurations.create("nativeImage" + prefix + "Classpath", c -> {
        c.setCanBeConsumed(false);
        c.setCanBeResolved(true);
        c.extendsFrom(compileOnly);
        baseClasspath.getExtendsFrom().forEach(c::extendsFrom);
        c.attributes(attrs -> {
            AttributeContainer baseAttributes = baseClasspath.getAttributes();
            for (Attribute<?> attribute : baseAttributes.keySet()) {
                Attribute<Object> attr = (Attribute<Object>) attribute;
                Object value = baseAttributes.getAttribute(attr);
                attrs.attribute(attr, value);
            }
        });
    });
    compileOnly.getDependencies().add(project.getDependencies().create(project));
    return new NativeConfigurations(compileOnly, classpath);
}
Also used : NativeConfigurations(org.graalvm.buildtools.gradle.internal.NativeConfigurations) JavaExec(org.gradle.api.tasks.JavaExec) AgentConfiguration(org.graalvm.buildtools.gradle.dsl.AgentConfiguration) Configuration(org.gradle.api.artifacts.Configuration) Attribute(org.gradle.api.attributes.Attribute) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) AttributeContainer(org.gradle.api.attributes.AttributeContainer)

Example 7 with AttributeContainer

use of org.gradle.api.attributes.AttributeContainer in project spring-boot by spring-projects.

the class JavaPluginAction method configureDevelopmentOnlyConfiguration.

private void configureDevelopmentOnlyConfiguration(Project project) {
    Configuration developmentOnly = project.getConfigurations().create(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME);
    developmentOnly.setDescription("Configuration for development-only dependencies such as Spring Boot's DevTools.");
    Configuration runtimeClasspath = project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
    Configuration productionRuntimeClasspath = project.getConfigurations().create(SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_CONFIGURATION_NAME);
    AttributeContainer attributes = productionRuntimeClasspath.getAttributes();
    ObjectFactory objectFactory = project.getObjects();
    attributes.attribute(Usage.USAGE_ATTRIBUTE, objectFactory.named(Usage.class, Usage.JAVA_RUNTIME));
    attributes.attribute(Bundling.BUNDLING_ATTRIBUTE, objectFactory.named(Bundling.class, Bundling.EXTERNAL));
    attributes.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objectFactory.named(LibraryElements.class, LibraryElements.JAR));
    productionRuntimeClasspath.setVisible(false);
    productionRuntimeClasspath.setExtendsFrom(runtimeClasspath.getExtendsFrom());
    productionRuntimeClasspath.setCanBeResolved(runtimeClasspath.isCanBeResolved());
    productionRuntimeClasspath.setCanBeConsumed(runtimeClasspath.isCanBeConsumed());
    runtimeClasspath.extendsFrom(developmentOnly);
}
Also used : Bundling(org.gradle.api.attributes.Bundling) Usage(org.gradle.api.attributes.Usage) Configuration(org.gradle.api.artifacts.Configuration) ObjectFactory(org.gradle.api.model.ObjectFactory) AttributeContainer(org.gradle.api.attributes.AttributeContainer) LibraryElements(org.gradle.api.attributes.LibraryElements)

Example 8 with AttributeContainer

use of org.gradle.api.attributes.AttributeContainer in project gradle by gradle.

the class NativeBasePlugin method addOutgoingConfigurationForRuntimeUsage.

private void addOutgoingConfigurationForRuntimeUsage(SoftwareComponentContainer components, final ConfigurationContainer configurations) {
    components.withType(ConfigurableComponentWithRuntimeUsage.class, component -> {
        Names names = component.getNames();
        Configuration runtimeElements = configurations.create(names.withSuffix("runtimeElements"));
        runtimeElements.extendsFrom(component.getImplementationDependencies());
        runtimeElements.setCanBeResolved(false);
        AttributeContainer attributes = component.getRuntimeAttributes();
        copyAttributesTo(attributes, runtimeElements);
        if (component.hasRuntimeFile()) {
            runtimeElements.getOutgoing().artifact(component.getRuntimeFile());
        }
        component.getRuntimeElements().set(runtimeElements);
    });
}
Also used : ComponentWithNames(org.gradle.language.nativeplatform.internal.ComponentWithNames) Names(org.gradle.language.nativeplatform.internal.Names) Configuration(org.gradle.api.artifacts.Configuration) AttributeContainer(org.gradle.api.attributes.AttributeContainer)

Example 9 with AttributeContainer

use of org.gradle.api.attributes.AttributeContainer in project gradle by gradle.

the class NativeBasePlugin method addOutgoingConfigurationForLinkUsage.

private void addOutgoingConfigurationForLinkUsage(SoftwareComponentContainer components, final ConfigurationContainer configurations) {
    components.withType(ConfigurableComponentWithLinkUsage.class, component -> {
        Names names = component.getNames();
        Configuration linkElements = configurations.create(names.withSuffix("linkElements"));
        linkElements.extendsFrom(component.getImplementationDependencies());
        linkElements.setCanBeResolved(false);
        AttributeContainer attributes = component.getLinkAttributes();
        copyAttributesTo(attributes, linkElements);
        linkElements.getOutgoing().artifact(component.getLinkFile());
        component.getLinkElements().set(linkElements);
    });
}
Also used : ComponentWithNames(org.gradle.language.nativeplatform.internal.ComponentWithNames) Names(org.gradle.language.nativeplatform.internal.Names) Configuration(org.gradle.api.artifacts.Configuration) AttributeContainer(org.gradle.api.attributes.AttributeContainer)

Example 10 with AttributeContainer

use of org.gradle.api.attributes.AttributeContainer in project gradle by gradle.

the class WarPlugin method configureComponent.

private void configureComponent(Project project, PublishArtifact warArtifact) {
    AttributeContainer attributes = attributesFactory.mutable().attribute(Usage.USAGE_ATTRIBUTE, objectFactory.named(Usage.class, Usage.JAVA_RUNTIME));
    project.getComponents().add(objectFactory.newInstance(WebApplication.class, warArtifact, "master", attributes));
}
Also used : Usage(org.gradle.api.attributes.Usage) AttributeContainer(org.gradle.api.attributes.AttributeContainer) WebApplication(org.gradle.api.internal.java.WebApplication)

Aggregations

AttributeContainer (org.gradle.api.attributes.AttributeContainer)34 Usage (org.gradle.api.attributes.Usage)14 Configuration (org.gradle.api.artifacts.Configuration)13 Project (org.gradle.api.Project)7 DefaultUsageContext (org.gradle.language.cpp.internal.DefaultUsageContext)7 NativeVariantIdentity (org.gradle.language.cpp.internal.NativeVariantIdentity)7 Bundling (org.gradle.api.attributes.Bundling)6 Callable (java.util.concurrent.Callable)5 Action (org.gradle.api.Action)5 ObjectFactory (org.gradle.api.model.ObjectFactory)5 Provider (org.gradle.api.provider.Provider)5 OperatingSystemFamily (org.gradle.nativeplatform.OperatingSystemFamily)5 File (java.io.File)4 Set (java.util.Set)4 Attribute (org.gradle.api.attributes.Attribute)4 Category (org.gradle.api.attributes.Category)4 Task (org.gradle.api.Task)3 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)3 LibraryElements (org.gradle.api.attributes.LibraryElements)3 Capability (org.gradle.api.capabilities.Capability)3