Search in sources :

Example 1 with ConfigurationVariant

use of org.gradle.api.artifacts.ConfigurationVariant in project gradle by gradle.

the class JavaPlugin method createVariant.

private void createVariant(NamedDomainObjectContainer<ConfigurationVariant> variants, String name, String artifactType, PublishArtifact artifact) {
    ConfigurationVariant variant = variants.create(name);
    variant.getAttributes().attribute(ArtifactAttributes.ARTIFACT_FORMAT, artifactType);
    variant.artifact(artifact);
}
Also used : ConfigurationVariant(org.gradle.api.artifacts.ConfigurationVariant)

Example 2 with ConfigurationVariant

use of org.gradle.api.artifacts.ConfigurationVariant 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);
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) ConfigurationVariant(org.gradle.api.artifacts.ConfigurationVariant) Usage(org.gradle.api.attributes.Usage) Configuration(org.gradle.api.artifacts.Configuration) ConfigurationPublications(org.gradle.api.artifacts.ConfigurationPublications) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) File(java.io.File)

Example 3 with ConfigurationVariant

use of org.gradle.api.artifacts.ConfigurationVariant 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 4 with ConfigurationVariant

use of org.gradle.api.artifacts.ConfigurationVariant 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();
        }
    });
}
Also used : ConfigurationVariant(org.gradle.api.artifacts.ConfigurationVariant) ConfigurationPublications(org.gradle.api.artifacts.ConfigurationPublications) File(java.io.File)

Example 5 with ConfigurationVariant

use of org.gradle.api.artifacts.ConfigurationVariant 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();
        }
    });
}
Also used : ConfigurationVariant(org.gradle.api.artifacts.ConfigurationVariant) Usage(org.gradle.api.attributes.Usage) ConfigurationPublications(org.gradle.api.artifacts.ConfigurationPublications) File(java.io.File)

Aggregations

ConfigurationVariant (org.gradle.api.artifacts.ConfigurationVariant)6 File (java.io.File)4 ConfigurationPublications (org.gradle.api.artifacts.ConfigurationPublications)4 Usage (org.gradle.api.attributes.Usage)3 Configuration (org.gradle.api.artifacts.Configuration)1 LibraryElements (org.gradle.api.attributes.LibraryElements)1 ConfigurationVariantInternal (org.gradle.api.internal.artifacts.ConfigurationVariantInternal)1 JvmPluginsHelper (org.gradle.api.plugins.internal.JvmPluginsHelper)1 SourceSet (org.gradle.api.tasks.SourceSet)1 JavaCompile (org.gradle.api.tasks.compile.JavaCompile)1