Search in sources :

Example 1 with VersionCatalogBuilder

use of org.gradle.api.initialization.dsl.VersionCatalogBuilder in project gradle by gradle.

the class DefaultDependenciesAccessors method generateAccessors.

@Override
public void generateAccessors(List<VersionCatalogBuilder> builders, ClassLoaderScope classLoaderScope, Settings settings) {
    try {
        this.classLoaderScope = classLoaderScope;
        // this is used in tests only, shouldn't happen in real context
        this.models.clear();
        for (VersionCatalogBuilder builder : builders) {
            DefaultVersionCatalog model = ((VersionCatalogBuilderInternal) builder).build();
            models.add(model);
        }
        if (models.stream().anyMatch(DefaultVersionCatalog::isNotEmpty)) {
            for (DefaultVersionCatalog model : models) {
                if (model.isNotEmpty()) {
                    writeDependenciesAccessors(model);
                }
            }
        }
        if (featurePreviews.isFeatureEnabled(FeaturePreviews.Feature.TYPESAFE_PROJECT_ACCESSORS)) {
            IncubationLogger.incubatingFeatureUsed("Type-safe project accessors");
            writeProjectAccessors(((SettingsInternal) settings).getProjectRegistry());
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : VersionCatalogBuilder(org.gradle.api.initialization.dsl.VersionCatalogBuilder) VersionCatalogBuilderInternal(org.gradle.internal.management.VersionCatalogBuilderInternal) InvalidUserDataException(org.gradle.api.InvalidUserDataException)

Example 2 with VersionCatalogBuilder

use of org.gradle.api.initialization.dsl.VersionCatalogBuilder in project gradle by gradle.

the class BuildTreePreparingProjectsPreparer method generateDependenciesAccessorsAndAssignPluginVersions.

private void generateDependenciesAccessorsAndAssignPluginVersions(ServiceRegistry services, SettingsInternal settings, ClassLoaderScope classLoaderScope) {
    DependenciesAccessors accessors = services.get(DependenciesAccessors.class);
    DependencyResolutionManagementInternal dm = services.get(DependencyResolutionManagementInternal.class);
    dm.getDefaultLibrariesExtensionName().finalizeValue();
    String defaultLibrary = dm.getDefaultLibrariesExtensionName().get();
    File dependenciesFile = new File(settings.getSettingsDir(), "gradle/libs.versions.toml");
    if (dependenciesFile.exists()) {
        dm.versionCatalogs(catalogs -> {
            VersionCatalogBuilder builder = catalogs.findByName(defaultLibrary);
            if (builder == null) {
                builder = catalogs.create(defaultLibrary);
            }
            builder.from(services.get(FileCollectionFactory.class).fixed(dependenciesFile));
        });
    }
    accessors.generateAccessors(dm.getDependenciesModelBuilders(), classLoaderScope, settings);
}
Also used : VersionCatalogBuilder(org.gradle.api.initialization.dsl.VersionCatalogBuilder) DependenciesAccessors(org.gradle.initialization.DependenciesAccessors) DependencyResolutionManagementInternal(org.gradle.internal.management.DependencyResolutionManagementInternal) File(java.io.File)

Aggregations

VersionCatalogBuilder (org.gradle.api.initialization.dsl.VersionCatalogBuilder)2 File (java.io.File)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 DependenciesAccessors (org.gradle.initialization.DependenciesAccessors)1 DependencyResolutionManagementInternal (org.gradle.internal.management.DependencyResolutionManagementInternal)1 VersionCatalogBuilderInternal (org.gradle.internal.management.VersionCatalogBuilderInternal)1