Search in sources :

Example 1 with ConfigurationVariantInternal

use of org.gradle.api.internal.artifacts.ConfigurationVariantInternal in project gradle by gradle.

the class JavaPlugin method addRuntimeVariants.

private void addRuntimeVariants(Configuration configuration, PublishArtifact jarArtifact, final SourceSet sourceSet, final Provider<ProcessResources> processResources) {
    ConfigurationPublications publications = configuration.getOutgoing();
    // Configure an implicit variant
    publications.getArtifacts().add(jarArtifact);
    publications.getAttributes().attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.JAR_TYPE);
    // Define some additional variants
    jvmServices.configureClassesDirectoryVariant(sourceSet.getRuntimeElementsConfigurationName(), sourceSet);
    NamedDomainObjectContainer<ConfigurationVariant> runtimeVariants = publications.getVariants();
    ConfigurationVariantInternal resourcesVariant = (ConfigurationVariantInternal) runtimeVariants.create("resources");
    resourcesVariant.setDescription("Directories containing the project's assembled resource files for use at runtime.");
    resourcesVariant.getAttributes().attribute(USAGE_ATTRIBUTE, objectFactory.named(Usage.class, Usage.JAVA_RUNTIME));
    resourcesVariant.getAttributes().attribute(LIBRARY_ELEMENTS_ATTRIBUTE, objectFactory.named(LibraryElements.class, LibraryElements.RESOURCES));
    resourcesVariant.artifact(new JvmPluginsHelper.IntermediateJavaArtifact(ArtifactTypeDefinition.JVM_RESOURCES_DIRECTORY, processResources) {

        @Override
        public File getFile() {
            return processResources.get().getDestinationDir();
        }
    });
}
Also used : ConfigurationVariant(org.gradle.api.artifacts.ConfigurationVariant) Usage(org.gradle.api.attributes.Usage) ConfigurationPublications(org.gradle.api.artifacts.ConfigurationPublications) ConfigurationVariantInternal(org.gradle.api.internal.artifacts.ConfigurationVariantInternal) LibraryElements(org.gradle.api.attributes.LibraryElements) JvmPluginsHelper(org.gradle.api.plugins.internal.JvmPluginsHelper) File(java.io.File)

Example 2 with ConfigurationVariantInternal

use of org.gradle.api.internal.artifacts.ConfigurationVariantInternal in project gradle by gradle.

the class DefaultJvmPluginServices method registerClassesDirVariant.

private void registerClassesDirVariant(final SourceSet sourceSet, Configuration configuration) {
    // Define a classes variant to use for compilation
    ConfigurationPublications publications = configuration.getOutgoing();
    ConfigurationVariantInternal variant = (ConfigurationVariantInternal) publications.getVariants().maybeCreate("classes");
    variant.setDescription("Directories containing compiled class files for " + sourceSet.getName() + ".");
    variant.getAttributes().attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objectFactory.named(LibraryElements.class, LibraryElements.CLASSES));
    variant.artifactsProvider(new Factory<List<PublishArtifact>>() {

        @Nullable
        @Override
        public List<PublishArtifact> create() {
            Set<File> classesDirs = sourceSet.getOutput().getClassesDirs().getFiles();
            DefaultSourceSetOutput output = Cast.uncheckedCast(sourceSet.getOutput());
            TaskDependency classesContributors = output.getClassesContributors();
            ImmutableList.Builder<PublishArtifact> artifacts = ImmutableList.builderWithExpectedSize(classesDirs.size());
            for (File classesDir : classesDirs) {
                // this is an approximation: all "compiled" sources will use the same task dependency
                artifacts.add(new JvmPluginsHelper.IntermediateJavaArtifact(ArtifactTypeDefinition.JVM_CLASS_DIRECTORY, classesContributors) {

                    @Override
                    public File getFile() {
                        return classesDir;
                    }
                });
            }
            return artifacts.build();
        }
    });
}
Also used : TaskDependency(org.gradle.api.tasks.TaskDependency) Set(java.util.Set) SourceSet(org.gradle.api.tasks.SourceSet) HashSet(java.util.HashSet) ConfigurationVariantInternal(org.gradle.api.internal.artifacts.ConfigurationVariantInternal) ConfigurationPublications(org.gradle.api.artifacts.ConfigurationPublications) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) DefaultSourceSetOutput(org.gradle.api.internal.tasks.DefaultSourceSetOutput) LibraryElements(org.gradle.api.attributes.LibraryElements) File(java.io.File) Nullable(javax.annotation.Nullable)

Aggregations

File (java.io.File)2 ConfigurationPublications (org.gradle.api.artifacts.ConfigurationPublications)2 LibraryElements (org.gradle.api.attributes.LibraryElements)2 ConfigurationVariantInternal (org.gradle.api.internal.artifacts.ConfigurationVariantInternal)2 ImmutableList (com.google.common.collect.ImmutableList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Nullable (javax.annotation.Nullable)1 ConfigurationVariant (org.gradle.api.artifacts.ConfigurationVariant)1 Usage (org.gradle.api.attributes.Usage)1 DefaultSourceSetOutput (org.gradle.api.internal.tasks.DefaultSourceSetOutput)1 JvmPluginsHelper (org.gradle.api.plugins.internal.JvmPluginsHelper)1 SourceSet (org.gradle.api.tasks.SourceSet)1 TaskDependency (org.gradle.api.tasks.TaskDependency)1