Source:
private void doTestHttpClient(final Runnable test) throws Exception { final String classpath = System.getProperty( "java.class.path" ); final String[] paths = classpath.split( File.pathSeparator ); final Collection<URL> urls = new ArrayList<>( paths.length ); for ( final String path : paths ) { try { urls.add( new File(path).toURI().toURL() ); } catch ( final MalformedURLException e ) { fail( e.getMessage() ); } } final URLClassLoader loader = new URLClassLoader( urls.toArray( new URL[paths.length ] ) , new ClassLoader() { @Override protected Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { if ( name.startsWith( "org.apache.maven.wagon.shared.http" ) ) { throw new ClassNotFoundException(name); } return super.loadClass(name, resolve); } }); final Thread thread = Thread.currentThread(); final ClassLoader contextClassLoader = thread.getContextClassLoader(); thread.setContextClassLoader(loader); final String originalClass = System.getProperty( "maven.wagon.http.retryhandler.class", "auto" ); final String originalSentEnabled = System.getProperty( "maven.wagon.http.retryhandler.requestSentEnabled", "false" ); final String originalCount = System.getProperty( "maven.wagon.http.retryhandler.count", "3" ); final String originalExceptions = System.getProperty( "maven.wagon.http.retryhandler.nonRetryableClasses", InterruptedIOException.class.getName() + "," + UnknownHostException.class.getName() + "," + ConnectException.class.getName() + "," + SSLException.class.getName()); try { test.run(); } finally { loader.close(); thread.setContextClassLoader(contextClassLoader); System.setProperty( "maven.wagon.http.retryhandler.class", originalClass ); System.setProperty( "maven.wagon.http.retryhandler.requestSentEnabled", originalSentEnabled ); System.setProperty( "maven.wagon.http.retryhandler.count", originalCount ); System.setProperty( "maven.wagon.http.retryhandler.nonRetryableClasses", originalExceptions ); } }

Target:
private void doTestHttpClient( final Runnable test ) throws Exception { final String classpath = System.getProperty( "java.class.path" ); final String[] paths = classpath.split( File.pathSeparator ); final Collection<URL> urls = new ArrayList<>( paths.length ); for ( final String path : paths ) { try { urls.add( new File( path ).toURI().toURL() ); } catch ( final MalformedURLException e ) { fail( e.getMessage() ); } } final URLClassLoader loader = new URLClassLoader( urls.toArray( new URL[ paths.length ] ) , new ClassLoader() { @Override protected Class<?> loadClass( final String name, final boolean resolve ) throws ClassNotFoundException { if ( name.startsWith( "org.apache.maven.wagon.shared.http" ) ) { throw new ClassNotFoundException( name ); } return super.loadClass( name, resolve ); } }); final Thread thread = Thread.currentThread(); final ClassLoader contextClassLoader = thread.getContextClassLoader(); thread.setContextClassLoader( loader ); final String originalClass = System.getProperty( "maven.wagon.http.retryhandler.class", "default" ); final String originalSentEnabled = System.getProperty( "maven.wagon.http.retryhandler.requestSentEnabled", "false" ); final String originalCount = System.getProperty( "maven.wagon.http.retryhandler.count", "3" ); final String originalExceptions = System.getProperty( "maven.wagon.http.retryhandler.nonRetryableClasses", InterruptedIOException.class.getName() + "," + UnknownHostException.class.getName() + "," + ConnectException.class.getName() + "," + SSLException.class.getName()); try { test.run(); } finally { loader.close(); thread.setContextClassLoader( contextClassLoader ); System.setProperty( "maven.wagon.http.retryhandler.class", originalClass ); System.setProperty( "maven.wagon.http.retryhandler.requestSentEnabled", originalSentEnabled ); System.setProperty( "maven.wagon.http.retryhandler.count", originalCount ); System.setProperty( "maven.wagon.http.retryhandler.nonRetryableClasses", originalExceptions ); } }