Maven repository with stubs should be determined automatically
Maybe we can use pom.xml or settings.xml to automatically determine remote repositories? The question is how to deal in Gradle projects
Local repositories too.
@ksprider you're talking about the case where your local repo is in a different folder than the default?
@marcingrzejszczak Yes.
Maybe we can use pom.xml or settings.xml before use default /user.home/m2/repo if we have not set maven.repo.local env ?
but we already do sth like this, don't we? https://github.com/spring-cloud/spring-cloud-contract/blob/090546986693da11225020c02bcd8633fb9e74d6/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherFactories.java#L75-L96
although it doesn't really have any defaults so actually we don't
Yes. We do this actually. Buy not perfect.
Well, i just set maven.home and add maven.home\bin to path. And i update localRepository of settings.xml. It can not be performed well in settings() method because i have not set MAVEN_USER_SETTINGS_LOCATION or MAVEN_USER_SETTINGS_LOCATION.
Of course i can set MAVEN_USER_SETTINGS_LOCATION or MAVEN_USER_SETTINGS_LOCATION, then it can read the localRepository.
Maybe we can read the localRepository from settings.xml before request.setUserSettingsFile...
I still don't follow...
Maybe we can read the localRepository from settings.xml before request.setUserSettingsFile...
Here we build the local repo
LocalRepository localRepo = new LocalRepository(localRepositoryDirectory());
the directory is taken from
private static String localRepositoryDirectory() {
String localRepoLocationFromSettings = settings().getLocalRepository();
return System.getProperty(MAVEN_LOCAL_REPOSITORY_LOCATION, localRepoLocationFromSettings != null
? localRepoLocationFromSettings
: System.getProperty("user.home") + File.separator + ".m2" + File.separator + "repository");
}
Now let's take a look at settings()
private static Settings settings() {
SettingsBuilder builder = new DefaultSettingsBuilderFactory().newInstance();
SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
String user = System.getProperty(MAVEN_USER_SETTINGS_LOCATION);
if (user == null) {
request.setUserSettingsFile(new File(new File(System.getProperty("user.home")).getAbsoluteFile(),
File.separator + ".m2" + File.separator + "settings.xml"));
} else {
request.setUserSettingsFile(new File(user));
}
String global = System.getProperty(MAVEN_GLOBAL_SETTINGS_LOCATION);
if (global != null) {
request.setGlobalSettingsFile(new File(global));
}
SettingsBuildingResult result;
try {
result = builder.build(request);
} catch (SettingsBuildingException ex) {
throw new IllegalStateException(ex);
}
return result.getEffectiveSettings();
}
If you haven't overridden anything it will take into consideration your settings.xml. If you have the localRepository set there, it should be read.
I am so sorry. I made a mistake.
I mean that we can locate settings.xml from maven's default directory maven.home/conf after if (user == null) .
codes like this:
String user = System.getProperty(MAVEN_USER_SETTINGS_LOCATION);
if (user == null) {
if(null != System.getProperty("maven.home")){
request.setUserSettingsFile(new File(System.getProperty("maven.home") + File.separator + "conf" + File.separator + "settings.xml"));
} else {
request.setUserSettingsFile(new File(new File(System.getProperty("user.home")).getAbsoluteFile(), File.separator + ".m2" + File.separator + "settings.xml"));
}
} else {
request.setUserSettingsFile(new File(user));
}
Ok, now I understood what you are talking about. So you're saying that we don't care about the maven.home property?
ping @ksprider ?