Specify local maven repo without changing settings.xml

Hi guys, I’d like to use gradle to install a library into the a local maven repository other than the one specified in maven’s settings.xml. The location of this repository is defined in a system variable called M2_REPO. Changing the settings.xml is not an option, so it needs to be done from gradle only. So far i’ve come up with:

apply plugin: 'java'
apply plugin: 'maven'
  group = 'gtest'
version = '1.0'
sourceCompatibility = '1.6'
log4jV='1.2.16'
m2_repo = System.getenv()['M2_REPO']
  dependencies {
    compile "log4j:log4j:$log4jV"
}
  repositories {
  mavenRepo urls: "file://" + m2_repo
  mavenCentral()
}
  uploadArchives.repositories.mavenDeployer {
  repository(url: "file://" + m2_repo)
}
  task wrapper(type: Wrapper) {
  gradleVersion = '0.9.2'
}

and get the following output:

:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:uploadArchives
Uploading: gtest/gtest/1.0/gtest-1.0.jar to repository remote at file:///home/user/test-repo
Transferring 1K from remote
Uploaded 1K
  BUILD SUCCESSFUL
  Total time: 3.294 secs

So in principal it works. But unfortunately the library is not only installed in M2_REPO but also in /home/user/.m2/repository. Is there any way to prevent uploadArchives from doing this? Or any way to use the install task to do this? Either way is fine.

I’m currently using gradle 0.9.2 but it does the same with 1.0, and if i need to use 1.0 to get this to work, i won’t mind either.

Thanks in advance,

Myke

I think you’re running into http://issues.gradle.org/browse/GRADLE-2349. I’m not aware of a workaround atm.

cheers, René

Hi René, thanks for your answer. Seams your absolutely right.

Is there a way to pass the -Dmaven.repo.local=“path” to the mvn call?

Regards,

Myke

Gradle does not internally do “mvn” call. At the moment the -Dmaven.repo.local=“path” is not evaluated to locate the local maven repository. Under the hood, Gradle uses the maven settings builder api to detect the correct local maven repository. I’ve just tested the behaviour of the settings builder api and it seems that it ignores the maven.repo.local system property.

cheers;

Any plans on supporting the -Dmaven.repo.local=“path” modifier or equivalent?

1 Like