diff --git a/pom.xml b/pom.xml
index a5fc6365fc..b92a63d9fb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -37,6 +37,7 @@
spring-boot-actuator
spring-boot-starters
spring-boot-cli
+ spring-boot-maven-settings
diff --git a/spring-boot-cli/pom.xml b/spring-boot-cli/pom.xml
index dfe3686862..9b3d2c7e15 100644
--- a/spring-boot-cli/pom.xml
+++ b/spring-boot-cli/pom.xml
@@ -36,6 +36,11 @@
pom
import
+
+ ${project.groupId}
+ spring-boot-maven-settings
+ ${project.version}
+
org.codehaus.groovy
groovy-xml
diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java
index 28ec4a349f..6477080369 100644
--- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java
+++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java
@@ -22,6 +22,7 @@ import groovy.lang.GroovyClassLoader.ClassCollector;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -42,11 +43,9 @@ import org.codehaus.groovy.control.customizers.CompilationCustomizer;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
import org.codehaus.groovy.transform.ASTTransformation;
import org.codehaus.groovy.transform.ASTTransformationVisitor;
-import org.eclipse.aether.repository.RemoteRepository;
-import org.eclipse.aether.repository.RepositoryPolicy;
import org.springframework.boot.cli.compiler.grape.AetherGrapeEngine;
+import org.springframework.boot.cli.compiler.grape.AetherGrapeEngineFactory;
import org.springframework.boot.cli.compiler.grape.GrapeEngineInstaller;
-import org.springframework.boot.cli.compiler.grape.RepositoryConfiguration;
import org.springframework.boot.cli.compiler.transformation.DependencyAutoConfigurationTransformation;
import org.springframework.boot.cli.compiler.transformation.GroovyBeansTransformation;
import org.springframework.boot.cli.compiler.transformation.ResolveDependencyCoordinatesTransformation;
@@ -92,15 +91,17 @@ public class GroovyCompiler {
this.loader = createLoader(configuration);
this.coordinatesResolver = new PropertiesArtifactCoordinatesResolver(this.loader);
- GrapeEngineInstaller.install(new AetherGrapeEngine(this.loader,
- createRepositories(configuration.getRepositoryConfiguration())));
+
+ AetherGrapeEngine grapeEngine = AetherGrapeEngineFactory.create(this.loader,
+ configuration.getRepositoryConfiguration());
+
+ GrapeEngineInstaller.install(grapeEngine);
this.loader.getConfiguration().addCompilationCustomizers(
new CompilerAutoConfigureCustomizer());
if (configuration.isAutoconfigure()) {
- this.compilerAutoConfigurations = ServiceLoader.load(
- CompilerAutoConfiguration.class,
- GroovyCompiler.class.getClassLoader());
+ this.compilerAutoConfigurations = ServiceLoader
+ .load(CompilerAutoConfiguration.class);
}
else {
this.compilerAutoConfigurations = Collections.emptySet();
@@ -122,31 +123,29 @@ public class GroovyCompiler {
private ExtendedGroovyClassLoader createLoader(
GroovyCompilerConfiguration configuration) {
+
ExtendedGroovyClassLoader loader = new ExtendedGroovyClassLoader(
configuration.getScope());
+
+ for (URL url : getExistingUrls()) {
+ loader.addURL(url);
+ }
+
for (String classpath : configuration.getClasspath()) {
loader.addClasspath(classpath);
}
+
return loader;
}
- private List createRepositories(
- List repositoryConfigurations) {
- List repositories = new ArrayList(
- repositoryConfigurations.size());
- for (RepositoryConfiguration repositoryConfiguration : repositoryConfigurations) {
- RemoteRepository.Builder builder = new RemoteRepository.Builder(
- repositoryConfiguration.getName(), "default", repositoryConfiguration
- .getUri().toASCIIString());
-
- if (!repositoryConfiguration.getSnapshotsEnabled()) {
- builder.setSnapshotPolicy(new RepositoryPolicy(false,
- RepositoryPolicy.UPDATE_POLICY_NEVER,
- RepositoryPolicy.CHECKSUM_POLICY_IGNORE));
- }
- repositories.add(builder.build());
+ private URL[] getExistingUrls() {
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ if (tccl instanceof ExtendedGroovyClassLoader) {
+ return ((ExtendedGroovyClassLoader) tccl).getURLs();
+ }
+ else {
+ return new URL[0];
}
- return repositories;
}
public void addCompilationCustomizers(CompilationCustomizer... customizers) {
diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java
index fe24bc5e98..aad0c84782 100644
--- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java
+++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngine.java
@@ -29,34 +29,20 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
-import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
-import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.collection.CollectRequest;
-import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.graph.Exclusion;
-import org.eclipse.aether.impl.DefaultServiceLocator;
-import org.eclipse.aether.internal.impl.DefaultRepositorySystem;
-import org.eclipse.aether.repository.LocalRepository;
-import org.eclipse.aether.repository.LocalRepositoryManager;
-import org.eclipse.aether.repository.ProxySelector;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.aether.resolution.ArtifactResult;
import org.eclipse.aether.resolution.DependencyRequest;
import org.eclipse.aether.resolution.DependencyResult;
-import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
-import org.eclipse.aether.spi.connector.transport.TransporterFactory;
-import org.eclipse.aether.spi.locator.ServiceLocator;
-import org.eclipse.aether.transport.file.FileTransporterFactory;
-import org.eclipse.aether.transport.http.HttpTransporterFactory;
import org.eclipse.aether.util.artifact.JavaScopes;
import org.eclipse.aether.util.filter.DependencyFilterUtils;
-import org.springframework.util.StringUtils;
/**
* A {@link GrapeEngine} implementation that uses repositories;
- private ProxySelector proxySelector = new JreProxySelector();
-
public AetherGrapeEngine(GroovyClassLoader classLoader,
+ RepositorySystem repositorySystem,
+ DefaultRepositorySystemSession repositorySystemSession,
List remoteRepositories) {
this.classLoader = classLoader;
- this.repositorySystem = createServiceLocator().getService(RepositorySystem.class);
- DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
- LocalRepository localRepository = new LocalRepository(getM2RepoDirectory());
- LocalRepositoryManager localRepositoryManager = this.repositorySystem
- .newLocalRepositoryManager(session, localRepository);
- session.setLocalRepositoryManager(localRepositoryManager);
- session.setProxySelector(this.proxySelector);
- this.session = session;
+ this.repositorySystem = repositorySystem;
+ this.session = repositorySystemSession;
+
this.repositories = new ArrayList();
List remotes = new ArrayList(
remoteRepositories);
@@ -102,37 +83,8 @@ public class AetherGrapeEngine implements GrapeEngine {
for (RemoteRepository repository : remotes) {
addRepository(repository);
}
- this.progressReporter = getProgressReporter(session);
- }
- private ServiceLocator createServiceLocator() {
- DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
- locator.addService(RepositorySystem.class, DefaultRepositorySystem.class);
- locator.addService(RepositoryConnectorFactory.class,
- BasicRepositoryConnectorFactory.class);
- locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
- locator.addService(TransporterFactory.class, FileTransporterFactory.class);
- return locator;
- }
-
- private File getM2RepoDirectory() {
- return new File(getM2HomeDirectory(), "repository");
- }
-
- private File getM2HomeDirectory() {
- String grapeRoot = System.getProperty("grape.root");
- if (StringUtils.hasLength(grapeRoot)) {
- return new File(grapeRoot);
- }
- return getDefaultM2HomeDirectory();
- }
-
- private File getDefaultM2HomeDirectory() {
- String mavenRoot = System.getProperty("maven.home");
- if (StringUtils.hasLength(mavenRoot)) {
- return new File(mavenRoot);
- }
- return new File(System.getProperty("user.home"), ".m2");
+ this.progressReporter = getProgressReporter(this.session);
}
private ProgressReporter getProgressReporter(DefaultRepositorySystemSession session) {
@@ -268,7 +220,7 @@ public class AetherGrapeEngine implements GrapeEngine {
}
if (repository.getProxy() == null) {
RemoteRepository.Builder builder = new RemoteRepository.Builder(repository);
- builder.setProxy(this.proxySelector.getProxy(repository));
+ builder.setProxy(this.session.getProxySelector().getProxy(repository));
repository = builder.build();
}
this.repositories.add(0, repository);
diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineFactory.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineFactory.java
new file mode 100644
index 0000000000..5d36785d9a
--- /dev/null
+++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineFactory.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2012-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.cli.compiler.grape;
+
+import groovy.lang.GroovyClassLoader;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ServiceLoader;
+
+import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
+import org.eclipse.aether.impl.DefaultServiceLocator;
+import org.eclipse.aether.internal.impl.DefaultRepositorySystem;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.repository.RepositoryPolicy;
+import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
+import org.eclipse.aether.spi.connector.transport.TransporterFactory;
+import org.eclipse.aether.spi.locator.ServiceLocator;
+import org.eclipse.aether.transport.file.FileTransporterFactory;
+import org.eclipse.aether.transport.http.HttpTransporterFactory;
+
+/**
+ * Utility class to create a pre-configured {@link AetherGrapeEngine}.
+ *
+ * @author Andy Wilkinson
+ */
+public abstract class AetherGrapeEngineFactory {
+
+ public static AetherGrapeEngine create(GroovyClassLoader classLoader,
+ List repositoryConfigurations) {
+
+ RepositorySystem repositorySystem = createServiceLocator().getService(
+ RepositorySystem.class);
+
+ DefaultRepositorySystemSession repositorySystemSession = MavenRepositorySystemUtils
+ .newSession();
+
+ ServiceLoader autoConfigurations = ServiceLoader
+ .load(RepositorySystemSessionAutoConfiguration.class);
+
+ for (RepositorySystemSessionAutoConfiguration autoConfiguration : autoConfigurations) {
+ autoConfiguration.apply(repositorySystemSession, repositorySystem);
+ }
+
+ new DefaultRepositorySystemSessionAutoConfiguration().apply(
+ repositorySystemSession, repositorySystem);
+
+ return new AetherGrapeEngine(classLoader, repositorySystem,
+ repositorySystemSession, createRepositories(repositoryConfigurations));
+ }
+
+ private static ServiceLocator createServiceLocator() {
+ DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
+ locator.addService(RepositorySystem.class, DefaultRepositorySystem.class);
+ locator.addService(RepositoryConnectorFactory.class,
+ BasicRepositoryConnectorFactory.class);
+ locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
+ locator.addService(TransporterFactory.class, FileTransporterFactory.class);
+ return locator;
+ }
+
+ private static List createRepositories(
+ List repositoryConfigurations) {
+ List repositories = new ArrayList(
+ repositoryConfigurations.size());
+ for (RepositoryConfiguration repositoryConfiguration : repositoryConfigurations) {
+ RemoteRepository.Builder builder = new RemoteRepository.Builder(
+ repositoryConfiguration.getName(), "default", repositoryConfiguration
+ .getUri().toASCIIString());
+
+ if (!repositoryConfiguration.getSnapshotsEnabled()) {
+ builder.setSnapshotPolicy(new RepositoryPolicy(false,
+ RepositoryPolicy.UPDATE_POLICY_NEVER,
+ RepositoryPolicy.CHECKSUM_POLICY_IGNORE));
+ }
+ repositories.add(builder.build());
+ }
+ return repositories;
+ }
+}
diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/DefaultRepositorySystemSessionAutoConfiguration.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/DefaultRepositorySystemSessionAutoConfiguration.java
new file mode 100644
index 0000000000..26806b8c2f
--- /dev/null
+++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/DefaultRepositorySystemSessionAutoConfiguration.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2012-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.cli.compiler.grape;
+
+import java.io.File;
+
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.repository.LocalRepository;
+import org.eclipse.aether.repository.LocalRepositoryManager;
+import org.springframework.util.StringUtils;
+
+/**
+ * A {@link RepositorySystemSessionAutoConfiguration} that, in the absence of any
+ * configuration, applies sensible defaults.
+ *
+ * @author Andy Wilkinson
+ */
+public class DefaultRepositorySystemSessionAutoConfiguration implements
+ RepositorySystemSessionAutoConfiguration {
+
+ @Override
+ public void apply(DefaultRepositorySystemSession session,
+ RepositorySystem repositorySystem) {
+
+ if (session.getLocalRepositoryManager() == null) {
+ LocalRepository localRepository = new LocalRepository(getM2RepoDirectory());
+ LocalRepositoryManager localRepositoryManager = repositorySystem
+ .newLocalRepositoryManager(session, localRepository);
+ session.setLocalRepositoryManager(localRepositoryManager);
+ }
+
+ if (session.getProxySelector() == null) {
+ session.setProxySelector(new JreProxySelector());
+ }
+ }
+
+ private File getM2RepoDirectory() {
+ return new File(getM2HomeDirectory(), "repository");
+ }
+
+ private File getM2HomeDirectory() {
+ String grapeRoot = System.getProperty("grape.root");
+ if (StringUtils.hasLength(grapeRoot)) {
+ return new File(grapeRoot);
+ }
+ return getDefaultM2HomeDirectory();
+ }
+
+ private File getDefaultM2HomeDirectory() {
+ String mavenRoot = System.getProperty("maven.home");
+ if (StringUtils.hasLength(mavenRoot)) {
+ return new File(mavenRoot);
+ }
+ return new File(System.getProperty("user.home"), ".m2");
+ }
+}
diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/RepositorySystemSessionAutoConfiguration.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/RepositorySystemSessionAutoConfiguration.java
new file mode 100644
index 0000000000..bd75340b08
--- /dev/null
+++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/grape/RepositorySystemSessionAutoConfiguration.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2012-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.cli.compiler.grape;
+
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystem;
+
+/**
+ * Strategy that can be used to apply some auto-configuration during the installation of
+ * an {@link AetherGrapeEngine}.
+ *
+ * @author Andy Wilkinson
+ */
+public interface RepositorySystemSessionAutoConfiguration {
+
+ /**
+ * Apply the configuration
+ */
+ void apply(DefaultRepositorySystemSession session, RepositorySystem repositorySystem);
+
+}
diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java
index 2debedf152..c47c4edefd 100644
--- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java
+++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java
@@ -18,11 +18,11 @@ package org.springframework.boot.cli.compiler.grape;
import groovy.lang.GroovyClassLoader;
+import java.net.URI;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
-import org.eclipse.aether.repository.RemoteRepository;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -36,9 +36,9 @@ public class AetherGrapeEngineTests {
private final GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
- private final AetherGrapeEngine grapeEngine = new AetherGrapeEngine(
- this.groovyClassLoader, Arrays.asList(new RemoteRepository.Builder("central",
- "default", "http://repo1.maven.org/maven2/").build()));
+ private final AetherGrapeEngine grapeEngine = AetherGrapeEngineFactory.create(
+ this.groovyClassLoader, Arrays.asList(new RepositoryConfiguration("central",
+ URI.create("http://repo1.maven.org/maven2"), false)));
@Test
public void dependencyResolution() {
diff --git a/spring-boot-maven-settings/pom.xml b/spring-boot-maven-settings/pom.xml
new file mode 100644
index 0000000000..4adc4cfa08
--- /dev/null
+++ b/spring-boot-maven-settings/pom.xml
@@ -0,0 +1,35 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-parent
+ 0.5.0.BUILD-SNAPSHOT
+ ../spring-boot-parent
+
+ spring-boot-maven-settings
+ jar
+
+
+
+ org.apache.maven
+ maven-settings-builder
+
+
+ org.eclipse.aether
+ aether-api
+
+
+ org.eclipse.aether
+ aether-util
+
+
+
+ ${project.groupId}
+ spring-boot-cli
+ ${project.version}
+ provided
+
+
+
diff --git a/spring-boot-maven-settings/src/main/java/org/springframework/boot/maven/settings/SettingsXmlRepositorySystemSessionAutoConfiguration.java b/spring-boot-maven-settings/src/main/java/org/springframework/boot/maven/settings/SettingsXmlRepositorySystemSessionAutoConfiguration.java
new file mode 100644
index 0000000000..24745451e8
--- /dev/null
+++ b/spring-boot-maven-settings/src/main/java/org/springframework/boot/maven/settings/SettingsXmlRepositorySystemSessionAutoConfiguration.java
@@ -0,0 +1,113 @@
+package org.springframework.boot.maven.settings;
+
+import java.io.File;
+
+import org.apache.maven.settings.Mirror;
+import org.apache.maven.settings.Proxy;
+import org.apache.maven.settings.Server;
+import org.apache.maven.settings.Settings;
+import org.apache.maven.settings.building.DefaultSettingsBuilderFactory;
+import org.apache.maven.settings.building.DefaultSettingsBuildingRequest;
+import org.apache.maven.settings.building.SettingsBuildingException;
+import org.apache.maven.settings.building.SettingsBuildingRequest;
+import org.apache.maven.settings.building.SettingsBuildingResult;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.repository.Authentication;
+import org.eclipse.aether.repository.AuthenticationSelector;
+import org.eclipse.aether.repository.LocalRepository;
+import org.eclipse.aether.repository.MirrorSelector;
+import org.eclipse.aether.repository.ProxySelector;
+import org.eclipse.aether.util.repository.AuthenticationBuilder;
+import org.eclipse.aether.util.repository.ConservativeAuthenticationSelector;
+import org.eclipse.aether.util.repository.DefaultAuthenticationSelector;
+import org.eclipse.aether.util.repository.DefaultMirrorSelector;
+import org.eclipse.aether.util.repository.DefaultProxySelector;
+import org.springframework.boot.cli.compiler.grape.RepositorySystemSessionAutoConfiguration;
+
+/**
+ * Auto-configuration for a RepositorySystemSession that uses Maven's settings.xml to
+ * determine the configuration settings
+ *
+ * @author Andy Wilkinson
+ */
+public class SettingsXmlRepositorySystemSessionAutoConfiguration implements
+ RepositorySystemSessionAutoConfiguration {
+
+ @Override
+ public void apply(DefaultRepositorySystemSession session,
+ RepositorySystem repositorySystem) {
+ Settings settings = loadSettings();
+
+ session.setOffline(settings.isOffline());
+ session.setMirrorSelector(createMirrorSelector(settings));
+ session.setAuthenticationSelector(createAuthenticationSelector(settings));
+ session.setProxySelector(createProxySelector(settings));
+
+ String localRepository = settings.getLocalRepository();
+
+ if (localRepository != null) {
+ session.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager(
+ session, new LocalRepository(localRepository)));
+ }
+ }
+
+ private Settings loadSettings() {
+ SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
+
+ File userSettingsFile = new File(System.getProperty("user.home"),
+ ".m2/settings.xml");
+
+ request.setUserSettingsFile(userSettingsFile);
+
+ SettingsBuildingResult result;
+ try {
+ result = new DefaultSettingsBuilderFactory().newInstance().build(request);
+ }
+ catch (SettingsBuildingException e) {
+ throw new IllegalStateException("Failed to build settings from "
+ + userSettingsFile, e);
+ }
+
+ return result.getEffectiveSettings();
+ }
+
+ private MirrorSelector createMirrorSelector(Settings settings) {
+ DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector();
+ for (Mirror mirror : settings.getMirrors()) {
+ mirrorSelector.add(mirror.getId(), mirror.getUrl(), mirror.getLayout(),
+ false, mirror.getMirrorOf(), mirror.getMirrorOfLayouts());
+ }
+ return mirrorSelector;
+ }
+
+ private AuthenticationSelector createAuthenticationSelector(Settings settings) {
+ DefaultAuthenticationSelector authenticationSelector = new DefaultAuthenticationSelector();
+
+ for (Server server : settings.getServers()) {
+ AuthenticationBuilder auth = new AuthenticationBuilder();
+ auth.addUsername(server.getUsername()).addPassword(server.getPassword());
+ auth.addPrivateKey(server.getPrivateKey(), server.getPassphrase());
+ authenticationSelector.add(server.getId(), auth.build());
+ }
+
+ return new ConservativeAuthenticationSelector(authenticationSelector);
+ }
+
+ private ProxySelector createProxySelector(Settings settings) {
+ DefaultProxySelector proxySelector = new DefaultProxySelector();
+
+ for (Proxy proxy : settings.getProxies()) {
+ Authentication authentication = new AuthenticationBuilder()
+ .addUsername(proxy.getUsername()).addPassword(proxy.getPassword())
+ .build();
+
+ proxySelector.add(
+ new org.eclipse.aether.repository.Proxy(proxy.getProtocol(), proxy
+ .getHost(), proxy.getPort(), authentication), proxy
+ .getNonProxyHosts());
+ }
+
+ return proxySelector;
+ }
+}
diff --git a/spring-boot-maven-settings/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.grape.RepositorySystemSessionAutoConfiguration b/spring-boot-maven-settings/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.grape.RepositorySystemSessionAutoConfiguration
new file mode 100644
index 0000000000..10fb8b41be
--- /dev/null
+++ b/spring-boot-maven-settings/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.grape.RepositorySystemSessionAutoConfiguration
@@ -0,0 +1 @@
+org.springframework.boot.maven.settings.SettingsXmlRepositorySystemSessionAutoConfiguration
\ No newline at end of file
diff --git a/spring-boot-maven-settings/src/test/java/org/springframework/boot/maven/settings/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java b/spring-boot-maven-settings/src/test/java/org/springframework/boot/maven/settings/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java
new file mode 100644
index 0000000000..b6aea41ed8
--- /dev/null
+++ b/spring-boot-maven-settings/src/test/java/org/springframework/boot/maven/settings/SettingsXmlRepositorySystemSessionAutoConfigurationTests.java
@@ -0,0 +1,39 @@
+package org.springframework.boot.maven.settings;
+
+import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
+import org.apache.maven.settings.building.SettingsBuildingException;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.repository.LocalRepositoryManager;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(MockitoJUnitRunner.class)
+public class SettingsXmlRepositorySystemSessionAutoConfigurationTests {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Mock
+ private RepositorySystem repositorySystem;
+
+ @Mock
+ LocalRepositoryManager localRepositoryManager;
+
+ @Test
+ public void basicSessionCustomization() throws SettingsBuildingException {
+ DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
+
+ new SettingsXmlRepositorySystemSessionAutoConfiguration().apply(session,
+ this.repositorySystem);
+
+ assertNotNull(session.getMirrorSelector());
+ assertNotNull(session.getProxySelector());
+ }
+}
diff --git a/spring-boot-parent/pom.xml b/spring-boot-parent/pom.xml
index 7a8c8ba421..ef6f3f6969 100644
--- a/spring-boot-parent/pom.xml
+++ b/spring-boot-parent/pom.xml
@@ -74,6 +74,11 @@
maven-settings
${maven.version}
+
+ org.apache.maven
+ maven-settings-builder
+ ${maven.version}
+
org.apache.maven.plugins
maven-shade-plugin