Search in sources :

Example 1 with JavaConfigurationVariantMapping

use of org.gradle.api.plugins.internal.JavaConfigurationVariantMapping in project gradle by gradle.

the class DefaultJvmVariantBuilder method configureDocumentationVariantWithArtifact.

public void configureDocumentationVariantWithArtifact(String variantName, @Nullable String name, @Nullable String displayName, String docsType, String jarTaskName, Object artifactSource, @Nullable AdhocComponentWithVariants component) {
    Configuration variant = configurations.maybeCreate(variantName);
    variant.setVisible(false);
    variant.setDescription(docsType + " elements for " + (displayName == null ? "main" : displayName) + ".");
    variant.setCanBeResolved(false);
    variant.setCanBeConsumed(true);
    jvmPluginServices.configureAttributes(variant, attributes -> attributes.documentation(docsType).runtimeUsage().withExternalDependencies());
    capabilities.forEach(variant.getOutgoing()::capability);
    if (!tasks.getNames().contains(jarTaskName)) {
        TaskProvider<Jar> jarTask = tasks.register(jarTaskName, Jar.class, jar -> {
            jar.setDescription("Assembles a jar archive containing the " + (displayName == null ? "main " + docsType + "." : (docsType + " of the '" + displayName + "'.")));
            jar.setGroup(BasePlugin.BUILD_GROUP);
            jar.from(artifactSource);
            jar.getArchiveClassifier().set(TextUtil.camelToKebabCase(name == null ? docsType : (name + "-" + docsType)));
        });
        if (tasks.getNames().contains(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)) {
            tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).configure(task -> task.dependsOn(jarTask));
        }
    }
    TaskProvider<Task> jar = tasks.named(jarTaskName);
    variant.getOutgoing().artifact(new LazyPublishArtifact(jar, project.getFileResolver()));
    if (published && component != null) {
        component.addVariantsFromConfiguration(variant, new JavaConfigurationVariantMapping("runtime", true));
    }
}
Also used : Task(org.gradle.api.Task) JvmPluginsHelper.configureJavaDocTask(org.gradle.api.plugins.internal.JvmPluginsHelper.configureJavaDocTask) LazyPublishArtifact(org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact) Configuration(org.gradle.api.artifacts.Configuration) JavaConfigurationVariantMapping(org.gradle.api.plugins.internal.JavaConfigurationVariantMapping) Jar(org.gradle.api.tasks.bundling.Jar)

Example 2 with JavaConfigurationVariantMapping

use of org.gradle.api.plugins.internal.JavaConfigurationVariantMapping in project gradle by gradle.

the class VersionCatalogPlugin method createPublication.

private void createPublication(Project project, TaskProvider<TomlFileGenerator> generator) {
    Configuration exported = project.getConfigurations().create(VERSION_CATALOG_ELEMENTS, cnf -> {
        cnf.setDescription("Artifacts for the version catalog");
        cnf.setCanBeConsumed(true);
        cnf.setCanBeResolved(false);
        cnf.getOutgoing().artifact(generator);
        cnf.attributes(attrs -> {
            attrs.attribute(Category.CATEGORY_ATTRIBUTE, project.getObjects().named(Category.class, Category.REGULAR_PLATFORM));
            attrs.attribute(Usage.USAGE_ATTRIBUTE, project.getObjects().named(Usage.class, Usage.VERSION_CATALOG));
        });
    });
    AdhocComponentWithVariants versionCatalog = softwareComponentFactory.adhoc("versionCatalog");
    project.getComponents().add(versionCatalog);
    versionCatalog.addVariantsFromConfiguration(exported, new JavaConfigurationVariantMapping("compile", true));
}
Also used : Usage(org.gradle.api.attributes.Usage) AdhocComponentWithVariants(org.gradle.api.component.AdhocComponentWithVariants) Category(org.gradle.api.attributes.Category) Configuration(org.gradle.api.artifacts.Configuration) JavaConfigurationVariantMapping(org.gradle.api.plugins.internal.JavaConfigurationVariantMapping)

Example 3 with JavaConfigurationVariantMapping

use of org.gradle.api.plugins.internal.JavaConfigurationVariantMapping in project gradle by gradle.

the class JavaPlatformPlugin method createSoftwareComponent.

private void createSoftwareComponent(Project project, Configuration apiElements, Configuration runtimeElements) {
    AdhocComponentWithVariants component = softwareComponentFactory.adhoc("javaPlatform");
    project.getComponents().add(component);
    component.addVariantsFromConfiguration(apiElements, new JavaConfigurationVariantMapping("compile", false));
    component.addVariantsFromConfiguration(runtimeElements, new JavaConfigurationVariantMapping("runtime", false));
}
Also used : AdhocComponentWithVariants(org.gradle.api.component.AdhocComponentWithVariants) JavaConfigurationVariantMapping(org.gradle.api.plugins.internal.JavaConfigurationVariantMapping)

Example 4 with JavaConfigurationVariantMapping

use of org.gradle.api.plugins.internal.JavaConfigurationVariantMapping in project gradle by gradle.

the class JavaPlugin method registerSoftwareComponents.

private void registerSoftwareComponents(Project project) {
    ConfigurationContainer configurations = project.getConfigurations();
    // the main "Java" component
    AdhocComponentWithVariants java = softwareComponentFactory.adhoc("java");
    java.addVariantsFromConfiguration(configurations.getByName(API_ELEMENTS_CONFIGURATION_NAME), new JavaConfigurationVariantMapping("compile", false));
    java.addVariantsFromConfiguration(configurations.getByName(RUNTIME_ELEMENTS_CONFIGURATION_NAME), new JavaConfigurationVariantMapping("runtime", false));
    project.getComponents().add(java);
}
Also used : AdhocComponentWithVariants(org.gradle.api.component.AdhocComponentWithVariants) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) JavaConfigurationVariantMapping(org.gradle.api.plugins.internal.JavaConfigurationVariantMapping)

Example 5 with JavaConfigurationVariantMapping

use of org.gradle.api.plugins.internal.JavaConfigurationVariantMapping in project gradle by gradle.

the class DefaultJvmVariantBuilder method build.

void build() {
    SourceSet sourceSet = this.sourceSet == null ? sourceSets.maybeCreate(name) : this.sourceSet;
    boolean mainSourceSet = SourceSet.isMain(sourceSet);
    String apiConfigurationName;
    String implementationConfigurationName;
    String apiElementsConfigurationName;
    String runtimeElementsConfigurationName;
    String compileOnlyConfigurationName;
    String compileOnlyApiConfigurationName;
    String runtimeOnlyConfigurationName;
    if (mainSourceSet) {
        apiConfigurationName = name + "Api";
        implementationConfigurationName = name + "Implementation";
        apiElementsConfigurationName = apiConfigurationName + "Elements";
        runtimeElementsConfigurationName = name + "RuntimeElements";
        compileOnlyConfigurationName = name + "CompileOnly";
        compileOnlyApiConfigurationName = name + "CompileOnlyApi";
        runtimeOnlyConfigurationName = name + "RuntimeOnly";
    } else {
        apiConfigurationName = sourceSet.getApiConfigurationName();
        implementationConfigurationName = sourceSet.getImplementationConfigurationName();
        apiElementsConfigurationName = sourceSet.getApiElementsConfigurationName();
        runtimeElementsConfigurationName = sourceSet.getRuntimeElementsConfigurationName();
        compileOnlyConfigurationName = sourceSet.getCompileOnlyConfigurationName();
        compileOnlyApiConfigurationName = sourceSet.getCompileOnlyApiConfigurationName();
        runtimeOnlyConfigurationName = sourceSet.getRuntimeOnlyConfigurationName();
    }
    String displayName = this.displayName == null ? name : this.displayName;
    // In the general case, the following configurations are already created
    // but if we're using the "main" source set, it means that the component we're creating shares
    // the same source set (main) but declares its dependencies in its own buckets, so we need
    // to create them
    Configuration implementation = bucket("Implementation", implementationConfigurationName, displayName);
    Configuration compileOnly = bucket("Compile-Only", compileOnlyConfigurationName, displayName);
    Configuration compileOnlyApi = bucket("Compile-Only API", compileOnlyApiConfigurationName, displayName);
    Configuration runtimeOnly = bucket("Runtime-Only", runtimeOnlyConfigurationName, displayName);
    TaskProvider<Task> jarTask = registerOrGetJarTask(sourceSet, displayName);
    Configuration api = exposeApi ? bucket("API", apiConfigurationName, displayName) : null;
    Configuration apiElements = exposeApi ? jvmPluginServices.createOutgoingElements(apiElementsConfigurationName, builder -> {
        builder.fromSourceSet(sourceSet).providesApi().withDescription("API elements for " + displayName).extendsFrom(api, compileOnlyApi).withCapabilities(capabilities).withClassDirectoryVariant().artifact(jarTask);
    }) : null;
    if (exposeApi) {
        implementation.extendsFrom(api);
    }
    Configuration runtimeElements = jvmPluginServices.createOutgoingElements(runtimeElementsConfigurationName, builder -> {
        builder.fromSourceSet(sourceSet).providesRuntime().withDescription("Runtime elements for " + displayName).extendsFrom(implementation, runtimeOnly).withCapabilities(capabilities).artifact(jarTask);
    });
    if (mainSourceSet) {
        // we need to wire the compile only and runtime only to the classpath configurations
        configurations.getByName(sourceSet.getCompileClasspathConfigurationName()).extendsFrom(implementation, compileOnly);
        configurations.getByName(sourceSet.getRuntimeClasspathConfigurationName()).extendsFrom(implementation, runtimeOnly);
        // and we also want the feature dependencies to be available on the test classpath
        configurations.getByName(JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME).extendsFrom(implementation, compileOnlyApi);
        configurations.getByName(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME).extendsFrom(implementation, runtimeOnly);
    }
    final AdhocComponentWithVariants component = findJavaComponent();
    JavaPluginExtension javaPluginExtension = project.getExtensions().findByType(JavaPluginExtension.class);
    configureJavaDocTask(name, sourceSet, tasks, javaPluginExtension);
    if (javadocJar) {
        configureDocumentationVariantWithArtifact(sourceSet.getJavadocElementsConfigurationName(), mainSourceSet ? null : name, displayName, JAVADOC, sourceSet.getJavadocJarTaskName(), tasks.named(sourceSet.getJavadocTaskName()), component);
    }
    if (sourcesJar) {
        configureDocumentationVariantWithArtifact(sourceSet.getSourcesElementsConfigurationName(), mainSourceSet ? null : name, displayName, SOURCES, sourceSet.getSourcesJarTaskName(), sourceSet.getAllSource(), component);
    }
    if (published && component != null) {
        if (apiElements != null) {
            component.addVariantsFromConfiguration(apiElements, new JavaConfigurationVariantMapping("compile", true));
        }
        component.addVariantsFromConfiguration(runtimeElements, new JavaConfigurationVariantMapping("runtime", true));
    }
}
Also used : SOURCES(org.gradle.api.attributes.DocsType.SOURCES) JavaPlugin(org.gradle.api.plugins.JavaPlugin) BasePlugin(org.gradle.api.plugins.BasePlugin) AdhocComponentWithVariants(org.gradle.api.component.AdhocComponentWithVariants) SourceSet(org.gradle.api.tasks.SourceSet) Inject(javax.inject.Inject) Configuration(org.gradle.api.artifacts.Configuration) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) Task(org.gradle.api.Task) Lists(com.google.common.collect.Lists) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) JavaConfigurationVariantMapping(org.gradle.api.plugins.internal.JavaConfigurationVariantMapping) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) TextUtil(org.gradle.util.internal.TextUtil) SoftwareComponentContainer(org.gradle.api.component.SoftwareComponentContainer) ProjectDerivedCapability(org.gradle.internal.component.external.model.ProjectDerivedCapability) Nullable(javax.annotation.Nullable) ImmutableCapability(org.gradle.internal.component.external.model.ImmutableCapability) LazyPublishArtifact(org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact) Jar(org.gradle.api.tasks.bundling.Jar) JAVADOC(org.gradle.api.attributes.DocsType.JAVADOC) List(java.util.List) JvmPluginsHelper.configureJavaDocTask(org.gradle.api.plugins.internal.JvmPluginsHelper.configureJavaDocTask) Capability(org.gradle.api.capabilities.Capability) TaskContainer(org.gradle.api.tasks.TaskContainer) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) InvalidUserDataException(org.gradle.api.InvalidUserDataException) SoftwareComponent(org.gradle.api.component.SoftwareComponent) SourceSet(org.gradle.api.tasks.SourceSet) Task(org.gradle.api.Task) JvmPluginsHelper.configureJavaDocTask(org.gradle.api.plugins.internal.JvmPluginsHelper.configureJavaDocTask) AdhocComponentWithVariants(org.gradle.api.component.AdhocComponentWithVariants) Configuration(org.gradle.api.artifacts.Configuration) JavaConfigurationVariantMapping(org.gradle.api.plugins.internal.JavaConfigurationVariantMapping) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension)

Aggregations

JavaConfigurationVariantMapping (org.gradle.api.plugins.internal.JavaConfigurationVariantMapping)5 AdhocComponentWithVariants (org.gradle.api.component.AdhocComponentWithVariants)4 Configuration (org.gradle.api.artifacts.Configuration)3 Task (org.gradle.api.Task)2 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)2 LazyPublishArtifact (org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact)2 JvmPluginsHelper.configureJavaDocTask (org.gradle.api.plugins.internal.JvmPluginsHelper.configureJavaDocTask)2 Jar (org.gradle.api.tasks.bundling.Jar)2 Lists (com.google.common.collect.Lists)1 List (java.util.List)1 Nullable (javax.annotation.Nullable)1 Inject (javax.inject.Inject)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 Category (org.gradle.api.attributes.Category)1 JAVADOC (org.gradle.api.attributes.DocsType.JAVADOC)1 SOURCES (org.gradle.api.attributes.DocsType.SOURCES)1 Usage (org.gradle.api.attributes.Usage)1 Capability (org.gradle.api.capabilities.Capability)1 SoftwareComponent (org.gradle.api.component.SoftwareComponent)1 SoftwareComponentContainer (org.gradle.api.component.SoftwareComponentContainer)1