diff --git a/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java b/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java index 9579697fc0..c0ef5bcf3e 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java @@ -66,7 +66,6 @@ import org.apache.maven.internal.impl.model.DefaultModelBuilder; import org.apache.maven.internal.impl.model.DefaultProfileSelector; import org.apache.maven.internal.impl.model.ProfileActivationFilePathInterpolator; import org.apache.maven.internal.impl.resolver.DefaultModelCache; -import org.apache.maven.internal.impl.resolver.DefaultModelRepositoryHolder; import org.apache.maven.model.v4.MavenModelVersion; import org.apache.maven.project.MavenProject; import org.eclipse.aether.RepositorySystem; @@ -139,9 +138,6 @@ class DefaultConsumerPomBuilder implements ConsumerPomBuilder { @Inject private ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator; - @Inject - private ModelResolver modelResolver; - Logger logger = LoggerFactory.getLogger(getClass()); @Override @@ -205,8 +201,7 @@ class DefaultConsumerPomBuilder implements ConsumerPomBuilder { request.source(ModelSource.fromPath(src)); request.validationLevel(ModelBuilderRequest.VALIDATION_LEVEL_MINIMAL); request.locationTracking(false); - request.modelResolver(modelResolver); - request.modelRepositoryHolder(iSession.getData().get(SessionData.key(DefaultModelRepositoryHolder.class))); + request.modelResolver(iSession.getData().get(SessionData.key(ModelResolver.class))); request.transformerContextBuilder(modelBuilder.newTransformerContextBuilder()); request.systemProperties(session.getSystemProperties()); request.userProperties(session.getUserProperties()); diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index eb4ccd71e8..f2f043ee7f 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -282,6 +282,7 @@ public class DefaultProjectBuilder implements ProjectBuilder { private final ModelTransformerContextBuilder transformerContextBuilder; private final ExecutorService executor; private final ModelCache modelCache; + private final ModelResolver modelResolver; BuildSession(ProjectBuildingRequest request, boolean localProjects) { this.request = request; @@ -299,6 +300,21 @@ public class DefaultProjectBuilder implements ProjectBuilder { } this.parentCache = new ConcurrentHashMap<>(); this.modelCache = DefaultModelCache.newInstance(session, true); + this.modelResolver = new ModelResolverWrapper() { + @Override + protected org.apache.maven.model.resolution.ModelResolver getResolver( + List repositories) { + return new ProjectModelResolver( + session, + RequestTrace.newChild(null, request), + repoSystem, + repositoryManager, + repositories, + request.getRepositoryMerging(), + modelPool, + parentCache); + } + }; } ExecutorService createExecutor(int parallelism) { @@ -1006,24 +1022,6 @@ public class DefaultProjectBuilder implements ProjectBuilder { private ModelBuilderRequest.ModelBuilderRequestBuilder getModelBuildingRequest() { ModelBuilderRequest.ModelBuilderRequestBuilder modelBuildingRequest = ModelBuilderRequest.builder(); - RequestTrace trace = RequestTrace.newChild(null, request).newChild(modelBuildingRequest); - - ModelResolver resolver = new ModelResolverWrapper() { - @Override - protected org.apache.maven.model.resolution.ModelResolver getResolver( - List repositories) { - return new ProjectModelResolver( - session, - trace, - repoSystem, - repositoryManager, - repositories, - request.getRepositoryMerging(), - modelPool, - parentCache); - } - }; - InternalSession internalSession = InternalSession.from(session); modelBuildingRequest.session(internalSession.withRemoteRepositories(request.getRemoteRepositories().stream() .map(r -> internalSession.getRemoteRepository(RepositoryUtils.toRepo(r))) @@ -1041,7 +1039,7 @@ public class DefaultProjectBuilder implements ProjectBuilder { modelBuildingRequest.systemProperties(toMap(request.getSystemProperties())); modelBuildingRequest.userProperties(toMap(request.getUserProperties())); // bv4: modelBuildingRequest.setBuildStartTime(request.getBuildStartTime()); - modelBuildingRequest.modelResolver(resolver); + modelBuildingRequest.modelResolver(modelResolver); DefaultModelRepositoryHolder holder = new DefaultModelRepositoryHolder( internalSession, DefaultModelRepositoryHolder.RepositoryMerging.valueOf( @@ -1049,7 +1047,6 @@ public class DefaultProjectBuilder implements ProjectBuilder { repositories.stream() .map(internalSession::getRemoteRepository) .toList()); - internalSession.getData().set(SessionData.key(DefaultModelRepositoryHolder.class), holder); modelBuildingRequest.modelRepositoryHolder(holder); modelBuildingRequest.modelCache(modelCache); modelBuildingRequest.transformerContextBuilder(transformerContextBuilder); @@ -1064,6 +1061,7 @@ public class DefaultProjectBuilder implements ProjectBuilder { } } */ + internalSession.getData().set(SessionData.key(ModelResolver.class), modelResolver); return modelBuildingRequest; }