Search in sources :

Example 1 with ConfigurationPublications

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);
}
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 2 with ConfigurationPublications

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();
        }
    });
}
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 3 with ConfigurationPublications

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

Example 4 with ConfigurationPublications

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

Example 5 with ConfigurationPublications

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);
}
Also used : ConfigurationPublications(org.gradle.api.artifacts.ConfigurationPublications)

Aggregations

ConfigurationPublications (org.gradle.api.artifacts.ConfigurationPublications)8 File (java.io.File)5 ConfigurationVariant (org.gradle.api.artifacts.ConfigurationVariant)4 Usage (org.gradle.api.attributes.Usage)3 LibraryElements (org.gradle.api.attributes.LibraryElements)2 ConfigurationVariantInternal (org.gradle.api.internal.artifacts.ConfigurationVariantInternal)2 SourceSet (org.gradle.api.tasks.SourceSet)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 Configuration (org.gradle.api.artifacts.Configuration)1 DefaultSourceSetOutput (org.gradle.api.internal.tasks.DefaultSourceSetOutput)1 JvmPluginsHelper (org.gradle.api.plugins.internal.JvmPluginsHelper)1 TaskDependency (org.gradle.api.tasks.TaskDependency)1 JavaCompile (org.gradle.api.tasks.compile.JavaCompile)1