use of org.gradle.api.artifacts.ConfigurationPublications in project gradle by gradle.
the class JavaLibraryPlugin method addApiToMainSourceSet.
private void addApiToMainSourceSet(Project project, 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);
final JavaCompile javaCompile = (JavaCompile) project.getTasks().getByPath(COMPILE_JAVA_TASK_NAME);
// Define a classes variant to use for compilation
ConfigurationPublications publications = apiElementsConfiguration.getOutgoing();
ConfigurationVariant variant = publications.getVariants().create("classes");
variant.getAttributes().attribute(Usage.USAGE_ATTRIBUTE, objectFactory.named(Usage.class, Usage.JAVA_API_CLASSES));
variant.artifact(new JavaPlugin.IntermediateJavaArtifact(ArtifactTypeDefinition.JVM_CLASS_DIRECTORY, javaCompile) {
@Override
public File getFile() {
return javaCompile.getDestinationDir();
}
});
Configuration implementationConfiguration = configurations.getByName(sourceSet.getImplementationConfigurationName());
implementationConfiguration.extendsFrom(apiConfiguration);
Configuration compileConfiguration = configurations.getByName(sourceSet.getCompileConfigurationName());
apiConfiguration.extendsFrom(compileConfiguration);
}
use of org.gradle.api.artifacts.ConfigurationPublications 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.artifacts.ConfigurationPublications in project gradle by gradle.
the class JavaPlugin method addVariants.
private void addVariants(Configuration configuration, ArchivePublishArtifact jarArtifact, final JavaCompile javaCompile, final ProcessResources processResources) {
ConfigurationPublications publications = configuration.getOutgoing();
// Configure an implicit variant
publications.getArtifacts().add(jarArtifact);
publications.getAttributes().attribute(ArtifactAttributes.ARTIFACT_FORMAT, JavaPlugin.JAR_TYPE);
// Define some additional variants
NamedDomainObjectContainer<ConfigurationVariant> runtimeVariants = publications.getVariants();
createVariant(runtimeVariants, "classes", JavaPlugin.CLASS_DIRECTORY, new IntermediateJavaArtifact(JavaPlugin.CLASS_DIRECTORY, javaCompile) {
@Override
public File getFile() {
return javaCompile.getDestinationDir();
}
});
createVariant(runtimeVariants, "resources", JavaPlugin.RESOURCES_DIRECTORY, new IntermediateJavaArtifact(JavaPlugin.RESOURCES_DIRECTORY, processResources) {
@Override
public File getFile() {
return processResources.getDestinationDir();
}
});
}
use of org.gradle.api.artifacts.ConfigurationPublications in project gradle by gradle.
the class JavaPlugin method addRuntimeVariants.
private void addRuntimeVariants(Configuration configuration, ArchivePublishArtifact jarArtifact, final JavaCompile javaCompile, final ProcessResources processResources) {
ConfigurationPublications publications = configuration.getOutgoing();
// Configure an implicit variant
publications.getArtifacts().add(jarArtifact);
publications.getAttributes().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.JAR_TYPE);
// Define some additional variants
NamedDomainObjectContainer<ConfigurationVariant> runtimeVariants = publications.getVariants();
ConfigurationVariant classesVariant = runtimeVariants.create("classes");
classesVariant.getAttributes().attribute(USAGE_ATTRIBUTE, objectFactory.named(Usage.class, Usage.JAVA_RUNTIME_CLASSES));
classesVariant.artifact(new IntermediateJavaArtifact(ArtifactTypeDefinition.JVM_CLASS_DIRECTORY, javaCompile) {
@Override
public File getFile() {
return javaCompile.getDestinationDir();
}
});
ConfigurationVariant resourcesVariant = runtimeVariants.create("resources");
resourcesVariant.getAttributes().attribute(USAGE_ATTRIBUTE, objectFactory.named(Usage.class, Usage.JAVA_RUNTIME_RESOURCES));
resourcesVariant.artifact(new IntermediateJavaArtifact(ArtifactTypeDefinition.JVM_RESOURCES_DIRECTORY, processResources) {
@Override
public File getFile() {
return processResources.getDestinationDir();
}
});
}
use of org.gradle.api.artifacts.ConfigurationPublications in project gradle by gradle.
the class JavaPlugin method addJar.
private void addJar(Configuration configuration, ArchivePublishArtifact jarArtifact) {
ConfigurationPublications publications = configuration.getOutgoing();
// Configure an implicit variant
publications.getArtifacts().add(jarArtifact);
publications.getAttributes().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.JAR_TYPE);
}
Aggregations