Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.util.PatternSet;
import org.gradle.internal.Factory;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

import java.io.File;

@ServiceScope(Scope.Project.class)
public class DefaultProjectLayout implements ProjectLayout, TaskFileVarFactory {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be dropped if we registered ProjectLayout as the service?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already register it as a service. The current reason is due to DefaultProject injecting the implementation, rather than the interfaces:

public abstract DefaultProjectLayout getLayout();

It seems, this is only due to the need to do DefaultProjectLayout#setBuildDirectory, which according to the comment should go away:

/**
* A temporary home. Should be on the public API somewhere
*/
public void setBuildDirectory(Object value) {
buildDir.set(fileResolver.resolve(value));
}

It's a nice catch, I'll fix it in a follow-up to avoid mixing non-trivial changes to this PR.

Copy link
Member Author

@alllex alllex Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the follow-up. It resolved your question, but also uncovered more questions about the buildDirectory setter


private final Directory settingsDir;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.file.collections.MinimalFileSet;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

@ServiceScope(Scope.Project.class)
public interface TaskFileVarFactory {
/**
* Creates a {@link ConfigurableFileCollection} that can be used as a task input.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.gradle.model.internal.registry;

import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;
import org.gradle.model.RuleSource;
import org.gradle.model.internal.core.ModelAction;
import org.gradle.model.internal.core.ModelActionRole;
Expand All @@ -28,6 +30,7 @@

import javax.annotation.Nullable;

@ServiceScope(Scope.Project.class)
public interface ModelRegistry {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
import org.gradle.internal.operations.BuildOperationRef;
import org.gradle.internal.operations.BuildOperationRunner;
import org.gradle.internal.service.ServiceRegistry;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;
import org.gradle.process.internal.worker.RequestHandler;

@ServiceScope(Scope.Project.class)
public class IsolatedClassloaderWorkerFactory implements WorkerFactory {
private final BuildOperationRunner buildOperationRunner;
private final ServiceRegistry internalServices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
import org.gradle.internal.operations.BuildOperationRef;
import org.gradle.internal.operations.BuildOperationRunner;
import org.gradle.internal.operations.CurrentBuildOperationRef;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

import javax.annotation.concurrent.ThreadSafe;

/**
* Controls the lifecycle of the worker daemon and provides access to it.
*/
@ServiceScope(Scope.Project.class)
@ThreadSafe
public class WorkerDaemonFactory implements WorkerFactory {
private final WorkerDaemonClientsManager clientsManager;
Expand All @@ -48,7 +51,7 @@ public DefaultWorkResult execute(IsolatedParametersActionExecutionSpec<?> spec,
// is never called) the cancellation handler will not stop daemons on a cancellation (as there is no danger of
// leaving one in an unsafe state).
workerDaemonClientCancellationHandler.start();

// wrap in build operation for logging startup failures
final WorkerDaemonClient client = CurrentBuildOperationRef.instance().with(parentBuildOperation, this::reserveClient);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

package org.gradle.internal.typeconversion;

import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

@ServiceScope(Scope.Project.class)
public interface TypeConverter {
/**
* @param type The target type. Should be the boxed type for primitives.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

package org.gradle.internal.logging.progress;

import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

import java.io.IOException;

@ServiceScope(Scope.Project.class)
public interface ProgressLoggingInputStreamListener {

void onProcessedBytes(int numberOfBytes) throws IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ class ServiceScopeValidatorWorkarounds {

"org.gradle.nativeplatform.platform.internal.NativePlatforms",
"org.gradle.nativeplatform.internal.NativePlatformResolver",
"org.gradle.nativeplatform.internal.DefaultTargetMachineFactory"
"org.gradle.nativeplatform.internal.DefaultTargetMachineFactory",

// Build init feature of converting Maven to Gradle build stops working with CC
"org.gradle.buildinit.plugins.internal.ProjectLayoutSetupRegistry"
));

public static boolean shouldSuppressValidation(Class<?> serviceType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@

package org.gradle.internal.enterprise.test.impl;

import org.gradle.internal.enterprise.test.TestTaskPropertiesService;
import org.gradle.internal.service.ServiceRegistration;
import org.gradle.internal.service.scopes.AbstractGradleModuleServices;

public class TestTaskPropertiesServices extends AbstractGradleModuleServices {

@Override
public void registerProjectServices(ServiceRegistration registration) {
registration.add(DefaultTestTaskPropertiesService.class);
registration.add(TestTaskPropertiesService.class, DefaultTestTaskPropertiesService.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@

package org.gradle.internal.snapshot;

import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

import java.nio.file.Path;

/**
* Snapshotting service which is used by test distribution.
*/
@ServiceScope(Scope.Project.class)
public interface SnapshottingService {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

import org.gradle.internal.service.ServiceRegistration;
import org.gradle.internal.service.scopes.AbstractGradleModuleServices;
import org.gradle.internal.snapshot.SnapshottingService;

public class SnapshottingServices extends AbstractGradleModuleServices {

@Override
public void registerProjectServices(ServiceRegistration registration) {
registration.add(DefaultSnapshottingService.class);
registration.add(SnapshottingService.class, DefaultSnapshottingService.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
import org.gradle.api.artifacts.component.ProjectComponentIdentifier;
import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.tasks.TaskDependencyContainer;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

import javax.annotation.Nullable;
import java.util.List;

/**
* This should merge into {@link org.gradle.api.internal.artifacts.ivyservice.projectmodule.ProjectPublicationRegistry}.
*/
@ServiceScope(Scope.Project.class)
public interface IdeArtifactRegistry {
/**
* Registers an IDE project model to be included in the IDE workspace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public void registerBuildTreeServices(ServiceRegistration registration) {

@Override
public void registerProjectServices(ServiceRegistration registration) {
registration.add(DefaultIdeArtifactRegistry.class);
registration.add(IdeArtifactRegistry.class, DefaultIdeArtifactRegistry.class);
}
}
2 changes: 1 addition & 1 deletion platforms/jvm/language-groovy/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
api(projects.platformBase)
api(projects.problemsApi)
api(projects.serviceProvider)
api(projects.stdlibJavaExtensions)
api(projects.toolchainsJvm)
api(projects.toolchainsJvmShared)
api(projects.workerMain)
Expand All @@ -31,7 +32,6 @@ dependencies {
implementation(projects.classloaders)
implementation(projects.concurrent)
implementation(projects.serviceLookup)
implementation(projects.stdlibJavaExtensions)
implementation(projects.fileCollections)
implementation(projects.logging)
implementation(projects.loggingApi)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.gradle.initialization.ClassLoaderRegistry;
import org.gradle.initialization.layout.ProjectCacheDir;
import org.gradle.internal.jvm.inspection.JvmVersionDetector;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;
import org.gradle.language.base.internal.compile.Compiler;
import org.gradle.language.base.internal.compile.CompilerFactory;
import org.gradle.process.internal.JavaForkOptionsFactory;
Expand All @@ -40,6 +42,7 @@
import java.io.File;
import java.util.List;

@ServiceScope(Scope.Project.class)
public class GroovyCompilerFactory implements CompilerFactory<GroovyJavaJointCompileSpec> {
private final WorkerDaemonFactory workerDaemonFactory;
private final IsolatedClassloaderWorkerFactory inProcessWorkerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@

import org.gradle.internal.Factory;
import org.gradle.internal.file.RelativeFilePathResolver;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

import javax.annotation.Nonnull;

@ServiceScope(Scope.Project.class)
public class CompilerOutputFileNamingSchemeFactory implements Factory<CompilerOutputFileNamingScheme> {
private final RelativeFilePathResolver fileResolver;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
package org.gradle.api.component;

import org.gradle.api.ExtensiblePolymorphicDomainObjectContainer;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

/**
* A Container that contains all of the Software Components produced by a Project.
*/
@ServiceScope(Scope.Project.class)
public interface SoftwareComponentContainer extends ExtensiblePolymorphicDomainObjectContainer<SoftwareComponent> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
*/
package org.gradle.api.internal.attributes;

import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@ServiceScope(Scope.Project.class)
public class AttributeDescriberRegistry {

private final List<AttributeDescriber> consumerAttributeDescribers = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
import org.gradle.api.internal.attributes.AttributeDescriberRegistry;
import org.gradle.api.internal.attributes.AttributesFactory;
import org.gradle.api.model.ObjectFactory;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

/**
* Provides access to services required for dependency resolution.
*/
@ServiceScope(Scope.Project.class)
public interface DependencyResolutionServices {
RepositoryHandler getResolveRepositoryHandler();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
package org.gradle.api.internal.artifacts.dsl.dependencies;

import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

@ServiceScope({Scope.Gradle.class, Scope.Project.class})
public interface ProjectFinder {
/**
* Locates the project with the provided path, failing if not found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.initialization.dsl.ScriptHandler;
import org.gradle.internal.classpath.ClassPath;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

@ServiceScope(Scope.Project.class)
public interface ScriptHandlerInternal extends ScriptHandler {

void addScriptClassPathDependency(Dependency dependency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
import org.gradle.api.plugins.AppliedPlugin;
import org.gradle.api.plugins.PluginContainer;
import org.gradle.api.plugins.PluginManager;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;
import org.gradle.plugin.use.PluginId;

import java.util.Optional;

@ServiceScope({Scope.Gradle.class, Scope.Settings.class, Scope.Project.class})
public interface PluginManagerInternal extends PluginManager {
void apply(PluginImplementation<?> plugin);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
package org.gradle.api.internal.project;

import org.gradle.api.Project;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

import javax.annotation.concurrent.NotThreadSafe;
import java.util.LinkedList;
import java.util.List;

@ServiceScope(Scope.Project.class)
@NotThreadSafe
public class DeferredProjectConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
import org.gradle.internal.model.RuleBasedPluginListener;
import org.gradle.internal.scan.UsedByScanPlugin;
import org.gradle.internal.service.ServiceRegistry;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceRegistryFactory;
import org.gradle.internal.service.scopes.ServiceScope;
import org.gradle.model.internal.registry.ModelRegistry;
import org.gradle.model.internal.registry.ModelRegistryScope;
import org.gradle.normalization.internal.InputNormalizationHandlerInternal;
Expand All @@ -55,6 +57,7 @@
import java.util.Set;

@UsedByScanPlugin("scan, test-retry")
@ServiceScope(Scope.Project.class)
public interface ProjectInternal extends Project, ProjectIdentifier, HasScriptServices, DomainObjectContext, ModelRegistryScope, PluginAwareInternal {

// These constants are defined here and not with the rest of their kind in HelpTasksPlugin because they are referenced
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@

import org.gradle.api.Task;
import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;
import org.gradle.model.internal.core.NamedEntityInstantiator;

@ServiceScope(Scope.Project.class)
public class TaskInstantiator implements NamedEntityInstantiator<Task> {
private static final Object[] NO_PARAMS = new Object[0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
import org.gradle.api.internal.PolymorphicDomainObjectContainerInternal;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.internal.metaobject.DynamicObject;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;
import org.gradle.model.internal.core.ModelPath;
import org.gradle.model.internal.type.ModelType;

import java.util.Collection;

@ServiceScope(Scope.Project.class)
public interface TaskContainerInternal extends TaskContainer, TaskResolver, PolymorphicDomainObjectContainerInternal<Task> {

// The path to the project's task container in the model registry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.gradle.api.internal.SettingsInternal;
import org.gradle.api.internal.plugins.PluginAwareInternal;
import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.internal.service.scopes.Scope;
import org.gradle.internal.service.scopes.ServiceScope;

import javax.annotation.Nullable;
import java.util.Locale;
Expand All @@ -30,6 +32,7 @@
* This is primarily used to support
* {@code ApplyScriptPluginBuildOperationType.Details} and {@code ApplyPluginBuildOperationType.Details}.
*/
@ServiceScope({Scope.Gradle.class, Scope.Settings.class, Scope.Project.class})
public abstract class ConfigurationTargetIdentifier {

private ConfigurationTargetIdentifier() {
Expand Down
Loading