From 474a470aa9c86910f430d00736e02bca5b61ed9c Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Fri, 18 Nov 2022 21:25:13 +0100 Subject: [PATCH] [MNG-7600] LocalRepositoryManager is created too early LocalRepositoryManager needs configurations from RepositorySystemSession so must be created after session configuration is finished. (cherry picked from commit b1c1f7556d6b66d984c4ed2c0eb723c9b99b38be) --- ...DefaultRepositorySystemSessionFactory.java | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java index 8c8e7fc12e..681d641adc 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java +++ b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java @@ -158,28 +158,6 @@ public class DefaultRepositorySystemSessionFactory session.setArtifactTypeRegistry( RepositoryUtils.newArtifactTypeRegistry( artifactHandlerManager ) ); - LocalRepository localRepo = new LocalRepository( request.getLocalRepository().getBasedir() ); - - if ( request.isUseLegacyLocalRepository() ) - { - try - { - session.setLocalRepositoryManager( simpleLocalRepoMgrFactory.newInstance( session, localRepo ) ); - logger.info( "Disabling enhanced local repository: using legacy is strongly discouraged to ensure" - + " build reproducibility." ); - - } - catch ( NoLocalRepositoryManagerException e ) - { - logger.error( "Failed to configure legacy local repository: falling back to default" ); - session.setLocalRepositoryManager( repoSystem.newLocalRepositoryManager( session, localRepo ) ); - } - } - else - { - session.setLocalRepositoryManager( repoSystem.newLocalRepositoryManager( session, localRepo ) ); - } - if ( request.getWorkspaceReader() != null ) { session.setWorkspaceReader( request.getWorkspaceReader() ); @@ -305,9 +283,35 @@ public class DefaultRepositorySystemSessionFactory mavenRepositorySystem.injectProxy( session, request.getPluginArtifactRepositories() ); mavenRepositorySystem.injectAuthentication( session, request.getPluginArtifactRepositories() ); + setUpLocalRepositoryManager( request, session ); + return session; } + private void setUpLocalRepositoryManager( MavenExecutionRequest request, DefaultRepositorySystemSession session ) + { + LocalRepository localRepo = new LocalRepository( request.getLocalRepository().getBasedir() ); + + if ( request.isUseLegacyLocalRepository() ) + { + try + { + session.setLocalRepositoryManager( simpleLocalRepoMgrFactory.newInstance( session, localRepo ) ); + logger.info( "Disabling enhanced local repository: using legacy is strongly discouraged to ensure" + + " build reproducibility." ); + } + catch ( NoLocalRepositoryManagerException e ) + { + logger.error( "Failed to configure legacy local repository: falling back to default" ); + session.setLocalRepositoryManager( repoSystem.newLocalRepositoryManager( session, localRepo ) ); + } + } + else + { + session.setLocalRepositoryManager( repoSystem.newLocalRepositoryManager( session, localRepo ) ); + } + } + private Map getPropertiesFromRequestedProfiles( MavenExecutionRequest request ) {