Search in sources :

Example 96 with Configuration

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

the class TestReportAggregationPlugin method apply.

@Override
public void apply(Project project) {
    project.getPluginManager().apply("org.gradle.reporting-base");
    final Configuration testAggregation = project.getConfigurations().create(TEST_REPORT_AGGREGATION_CONFIGURATION_NAME);
    testAggregation.setDescription("A configuration to collect test execution results");
    testAggregation.setVisible(false);
    testAggregation.setCanBeConsumed(false);
    testAggregation.setCanBeResolved(false);
    ReportingExtension reporting = project.getExtensions().getByType(ReportingExtension.class);
    reporting.getReports().registerBinding(AggregateTestReport.class, DefaultAggregateTestReport.class);
    ObjectFactory objects = project.getObjects();
    final DirectoryProperty testReportDirectory = objects.directoryProperty().convention(reporting.getBaseDirectory().dir(TestingBasePlugin.TESTS_DIR_NAME));
    // prepare testReportDirectory with a reasonable default, but override with JavaPluginExtension#testReportDirectory if available
    project.getPlugins().withId("java-base", plugin -> {
        JavaPluginExtension javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class);
        testReportDirectory.convention(javaPluginExtension.getTestReportDir());
    });
    // iterate and configure each user-specified report, creating a <reportName>Results configuration for each
    reporting.getReports().withType(AggregateTestReport.class).all(report -> {
        // A resolvable configuration to collect test results; typically named "testResults"
        Configuration testResultsConf = project.getConfigurations().create(report.getName() + "Results");
        testResultsConf.extendsFrom(testAggregation);
        testResultsConf.setDescription(String.format("Supplies test result data to the %s.  External library dependencies may appear as resolution failures, but this is expected behavior.", report.getName()));
        testResultsConf.setVisible(false);
        testResultsConf.setCanBeConsumed(false);
        testResultsConf.setCanBeResolved(true);
        testResultsConf.attributes(attributes -> {
            attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.class, Category.VERIFICATION));
            attributes.attributeProvider(TestSuiteType.TEST_SUITE_TYPE_ATTRIBUTE, report.getTestType().map(tt -> objects.named(TestSuiteType.class, tt)));
            attributes.attribute(VerificationType.VERIFICATION_TYPE_ATTRIBUTE, objects.named(VerificationType.class, VerificationType.TEST_RESULTS));
        });
        report.getReportTask().configure(task -> {
            Callable<FileCollection> testResults = () -> testResultsConf.getIncoming().artifactView(view -> {
                view.componentFilter(id -> id instanceof ProjectComponentIdentifier);
                view.lenient(true);
            }).getFiles();
            task.getTestResults().from(testResults);
            task.getDestinationDirectory().convention(testReportDirectory.dir(report.getTestType().map(tt -> tt + "/aggregated-results")));
        });
    });
    // convention for synthesizing reports based on existing test suites in "this" project
    project.getPlugins().withId("jvm-test-suite", plugin -> {
        // Depend on this project for aggregation
        project.getDependencies().add(TEST_REPORT_AGGREGATION_CONFIGURATION_NAME, project);
        TestingExtension testing = project.getExtensions().getByType(TestingExtension.class);
        ExtensiblePolymorphicDomainObjectContainer<TestSuite> testSuites = testing.getSuites();
        testSuites.withType(JvmTestSuite.class).all(testSuite -> {
            reporting.getReports().create(testSuite.getName() + "AggregateTestReport", AggregateTestReport.class, report -> {
                report.getTestType().convention(testSuite.getTestType());
            });
        });
    });
}
Also used : TestSuiteType(org.gradle.api.attributes.TestSuiteType) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) TestingBasePlugin(org.gradle.testing.base.plugins.TestingBasePlugin) ReportingExtension(org.gradle.api.reporting.ReportingExtension) Project(org.gradle.api.Project) Category(org.gradle.api.attributes.Category) DefaultAggregateTestReport(org.gradle.api.internal.tasks.testing.DefaultAggregateTestReport) TestingExtension(org.gradle.testing.base.TestingExtension) Callable(java.util.concurrent.Callable) AggregateTestReport(org.gradle.api.tasks.testing.AggregateTestReport) FileCollection(org.gradle.api.file.FileCollection) JvmTestSuite(org.gradle.api.plugins.jvm.JvmTestSuite) Configuration(org.gradle.api.artifacts.Configuration) TestSuite(org.gradle.testing.base.TestSuite) VerificationType(org.gradle.api.attributes.VerificationType) ObjectFactory(org.gradle.api.model.ObjectFactory) DirectoryProperty(org.gradle.api.file.DirectoryProperty) ExtensiblePolymorphicDomainObjectContainer(org.gradle.api.ExtensiblePolymorphicDomainObjectContainer) Incubating(org.gradle.api.Incubating) Plugin(org.gradle.api.Plugin) ReportingExtension(org.gradle.api.reporting.ReportingExtension) Category(org.gradle.api.attributes.Category) Configuration(org.gradle.api.artifacts.Configuration) TestingExtension(org.gradle.testing.base.TestingExtension) VerificationType(org.gradle.api.attributes.VerificationType) FileCollection(org.gradle.api.file.FileCollection) DirectoryProperty(org.gradle.api.file.DirectoryProperty) ObjectFactory(org.gradle.api.model.ObjectFactory) JvmTestSuite(org.gradle.api.plugins.jvm.JvmTestSuite) TestSuite(org.gradle.testing.base.TestSuite) DefaultAggregateTestReport(org.gradle.api.internal.tasks.testing.DefaultAggregateTestReport) AggregateTestReport(org.gradle.api.tasks.testing.AggregateTestReport) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) JvmTestSuite(org.gradle.api.plugins.jvm.JvmTestSuite)

Example 97 with Configuration

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

the class VersionCatalogPlugin method apply.

@Override
public void apply(Project project) {
    Configuration dependenciesConfiguration = createDependenciesConfiguration(project);
    CatalogExtensionInternal extension = createExtension(project, dependenciesConfiguration);
    TaskProvider<TomlFileGenerator> generator = createGenerator(project, extension);
    createPublication(project, generator);
}
Also used : CatalogExtensionInternal(org.gradle.api.plugins.catalog.internal.CatalogExtensionInternal) Configuration(org.gradle.api.artifacts.Configuration) TomlFileGenerator(org.gradle.api.plugins.catalog.internal.TomlFileGenerator)

Example 98 with Configuration

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

the class WarPlugin method apply.

@Override
public void apply(final Project project) {
    project.getPluginManager().apply(JavaPlugin.class);
    final WarPluginConvention pluginConvention = new DefaultWarPluginConvention(project);
    project.getConvention().getPlugins().put("war", pluginConvention);
    project.getTasks().withType(War.class).configureEach(task -> {
        task.getWebAppDirectory().convention(project.getLayout().dir(project.provider(() -> pluginConvention.getWebAppDir())));
        task.from(task.getWebAppDirectory());
        task.dependsOn((Callable) () -> project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath());
        task.classpath((Callable) () -> {
            FileCollection runtimeClasspath = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
            Configuration providedRuntime = project.getConfigurations().getByName(PROVIDED_RUNTIME_CONFIGURATION_NAME);
            return runtimeClasspath.minus(providedRuntime);
        });
    });
    TaskProvider<War> war = project.getTasks().register(WAR_TASK_NAME, War.class, warTask -> {
        warTask.setDescription("Generates a war archive with all the compiled classes, the web-app content and the libraries.");
        warTask.setGroup(BasePlugin.BUILD_GROUP);
    });
    PublishArtifact warArtifact = new LazyPublishArtifact(war, ((ProjectInternal) project).getFileResolver());
    project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(warArtifact);
    configureConfigurations(project.getConfigurations());
    configureComponent(project, warArtifact);
}
Also used : LazyPublishArtifact(org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact) DefaultArtifactPublicationSet(org.gradle.api.internal.plugins.DefaultArtifactPublicationSet) DefaultWarPluginConvention(org.gradle.api.plugins.internal.DefaultWarPluginConvention) Configuration(org.gradle.api.artifacts.Configuration) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) War(org.gradle.api.tasks.bundling.War) FileCollection(org.gradle.api.file.FileCollection) LazyPublishArtifact(org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) DefaultWarPluginConvention(org.gradle.api.plugins.internal.DefaultWarPluginConvention)

Example 99 with Configuration

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

the class JavaBasePlugin method defineConfigurationsForSourceSet.

private void defineConfigurationsForSourceSet(SourceSet sourceSet, ConfigurationContainer configurations) {
    String implementationConfigurationName = sourceSet.getImplementationConfigurationName();
    String runtimeOnlyConfigurationName = sourceSet.getRuntimeOnlyConfigurationName();
    String compileOnlyConfigurationName = sourceSet.getCompileOnlyConfigurationName();
    String compileClasspathConfigurationName = sourceSet.getCompileClasspathConfigurationName();
    String annotationProcessorConfigurationName = sourceSet.getAnnotationProcessorConfigurationName();
    String runtimeClasspathConfigurationName = sourceSet.getRuntimeClasspathConfigurationName();
    String sourceSetName = sourceSet.toString();
    Configuration implementationConfiguration = configurations.maybeCreate(implementationConfigurationName);
    implementationConfiguration.setVisible(false);
    implementationConfiguration.setDescription("Implementation only dependencies for " + sourceSetName + ".");
    implementationConfiguration.setCanBeConsumed(false);
    implementationConfiguration.setCanBeResolved(false);
    DeprecatableConfiguration compileOnlyConfiguration = (DeprecatableConfiguration) configurations.maybeCreate(compileOnlyConfigurationName);
    compileOnlyConfiguration.setVisible(false);
    compileOnlyConfiguration.setCanBeConsumed(false);
    compileOnlyConfiguration.setCanBeResolved(false);
    compileOnlyConfiguration.setDescription("Compile only dependencies for " + sourceSetName + ".");
    ConfigurationInternal compileClasspathConfiguration = (ConfigurationInternal) configurations.maybeCreate(compileClasspathConfigurationName);
    compileClasspathConfiguration.setVisible(false);
    compileClasspathConfiguration.extendsFrom(compileOnlyConfiguration, implementationConfiguration);
    compileClasspathConfiguration.setDescription("Compile classpath for " + sourceSetName + ".");
    compileClasspathConfiguration.setCanBeConsumed(false);
    jvmPluginServices.configureAsCompileClasspath(compileClasspathConfiguration);
    ConfigurationInternal annotationProcessorConfiguration = (ConfigurationInternal) configurations.maybeCreate(annotationProcessorConfigurationName);
    annotationProcessorConfiguration.setVisible(false);
    annotationProcessorConfiguration.setDescription("Annotation processors and their dependencies for " + sourceSetName + ".");
    annotationProcessorConfiguration.setCanBeConsumed(false);
    annotationProcessorConfiguration.setCanBeResolved(true);
    jvmPluginServices.configureAsRuntimeClasspath(annotationProcessorConfiguration);
    Configuration runtimeOnlyConfiguration = configurations.maybeCreate(runtimeOnlyConfigurationName);
    runtimeOnlyConfiguration.setVisible(false);
    runtimeOnlyConfiguration.setCanBeConsumed(false);
    runtimeOnlyConfiguration.setCanBeResolved(false);
    runtimeOnlyConfiguration.setDescription("Runtime only dependencies for " + sourceSetName + ".");
    ConfigurationInternal runtimeClasspathConfiguration = (ConfigurationInternal) configurations.maybeCreate(runtimeClasspathConfigurationName);
    runtimeClasspathConfiguration.setVisible(false);
    runtimeClasspathConfiguration.setCanBeConsumed(false);
    runtimeClasspathConfiguration.setCanBeResolved(true);
    runtimeClasspathConfiguration.setDescription("Runtime classpath of " + sourceSetName + ".");
    runtimeClasspathConfiguration.extendsFrom(runtimeOnlyConfiguration, implementationConfiguration);
    jvmPluginServices.configureAsRuntimeClasspath(runtimeClasspathConfiguration);
    sourceSet.setCompileClasspath(compileClasspathConfiguration);
    sourceSet.setRuntimeClasspath(sourceSet.getOutput().plus(runtimeClasspathConfiguration));
    sourceSet.setAnnotationProcessorPath(annotationProcessorConfiguration);
    compileClasspathConfiguration.deprecateForDeclaration(implementationConfigurationName, compileOnlyConfigurationName);
    runtimeClasspathConfiguration.deprecateForDeclaration(implementationConfigurationName, compileOnlyConfigurationName, runtimeOnlyConfigurationName);
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) ConfigurationInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationInternal)

Example 100 with Configuration

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

the class JavaPlatformPlugin method createConsumableApi.

private Configuration createConsumableApi(Project project, ConfigurationContainer configurations, Configuration api, String name, String platformKind) {
    Configuration apiElements = configurations.create(name, AS_CONSUMABLE_CONFIGURATION);
    apiElements.extendsFrom(api);
    declareConfigurationUsage(project.getObjects(), apiElements, Usage.JAVA_API);
    declareConfigurationCategory(project.getObjects(), apiElements, platformKind);
    return apiElements;
}
Also used : Configuration(org.gradle.api.artifacts.Configuration)

Aggregations

Configuration (org.gradle.api.artifacts.Configuration)431 File (java.io.File)121 Project (org.gradle.api.Project)116 Dependency (org.gradle.api.artifacts.Dependency)66 SourceSet (org.gradle.api.tasks.SourceSet)61 Task (org.gradle.api.Task)54 List (java.util.List)53 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)52 Set (java.util.Set)51 Collectors (java.util.stream.Collectors)50 Map (java.util.Map)49 Plugin (org.gradle.api.Plugin)49 ArrayList (java.util.ArrayList)43 IOException (java.io.IOException)41 TaskProvider (org.gradle.api.tasks.TaskProvider)41 FileCollection (org.gradle.api.file.FileCollection)40 HashSet (java.util.HashSet)39 SourceSetContainer (org.gradle.api.tasks.SourceSetContainer)39 GradleException (org.gradle.api.GradleException)38 HashMap (java.util.HashMap)37