[GRADLE-1900] Apply the repo location from the maven config in mavenLocal() Created: 08/Nov/11 Updated: 04/Jan/13 Resolved: 24/Feb/12 |
|
Status: | Resolved |
Project: | Gradle |
Affects Version/s: | 1.0-milestone-5 |
Fix Version/s: | 1.0-milestone-9 |
Type: | Improvement | ||
Reporter: | Mike M. | Assignee: | Peter Niederwieser |
Resolution: | Fixed | Votes: | 0 |
Description |
We have the situation where our CI server uses a custom maven localRepository location, configured in a settings.xml file in the conf subdirectory of the maven home dir. The Maven Ant Tasks, which we used before switching to Gradle, and which Gradle uses internally in the Maven plugin, read and apply the settings in this file. However, Gradle's mavenLocal() repository location does not. So let's say I use the Maven Plugin's install task in Gradle project A and the mavenLocal() repository location in Gradle project B. Project B has an external dependency on artifacts from Project A. Project A will install its artifacts into the local repository configured in my $M2_HOME/conf/settings.xml file, whereas project B will always look them up in my ~/.m2/repository/ folder. Since Gradle supports both directions, publishing and retrieving from Maven repositories out of the box, I think the behavior should be symmetrical here. It should just work without me having to manually specify repository locations in one of the two directions. I've written a little workaround that mimics the behavior of the Maven Ant Tasks in looking up and applying the localRepository location from the maven config file locations: buildscript { repositories { project.myMavenLocal() } ... } myMavenLocal = { File mavenSettingsFile = new File(System.getProperty("user.home") + "/.m2/settings.xml"); if (!mavenSettingsFile.exists() && System.getenv().get("M2_HOME") != null) { println "" + mavenSettingsFile + " doesn't exist..." mavenSettingsFile = new File(System.getenv().get("M2_HOME") + "/conf/settings.xml"); } if (mavenSettingsFile.exists()) { println "" + mavenSettingsFile + " exists..." String repoLocation = new XmlSlurper().parse(mavenSettingsFile).localRepository.text(); println "Repo location is " + repoLocation if ( repoLocation != null && repoLocation != "" ) { String localMavenRepo = 'file://' + new File(repoLocation).getAbsolutePath(); println "Absolute repo location is " + localMavenRepo return repositories.mavenRepo(url: localMavenRepo) } } println "Falling back to default method..." return repositories.mavenLocal(); } |
Comments |
Comment by Mike M. [ 08/Nov/11 ] |
This issue is related to |
Comment by Peter Niederwieser [ 24/Feb/12 ] |
$M2_HOME/conf/settings.xml is now considered as well. Also, placeholders for system properties and environment variables in the repository path are resolved. |