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();
}
});
}
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();
}
});
}
Aggregations