From 8fd8a05aad65df05587cfed2b0a870ece2efa309 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 60c6cf17a050..d00bdc09aee1 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 @@ -132,28 +132,6 @@ else if ( request.isUpdateSnapshots() ) 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() ); @@ -240,9 +218,35 @@ else if ( request.isUpdateSnapshots() ) 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 String getUserAgent() { String version = runtimeInformation.getMavenVersion();