mavenLocal repository location cannot be changed?

(Ken Taylor) #1

In the DSL docs for 5.3.1 RepositoryHandler.mavenLocal() it lists where the plugin looks for the location of the repository. This info is no longer correct apparantly. We’ve tried every possible way to change the repo location but publishing always goes to ~/.m2/repository. The only file we use is per project and it specifies the repo location as well. We’ve also put a settings.xml in ~/.m2, specifying the repo location. We’ve set the maven.repo.local env var in the shell. Nothing works! mavenLocal() does not have a URL parameter so you can’t set it that way either. It used to work in Gradle 4. Any ideas?

(uklance) #2
repositories {
   maven {
      url = file('/path/to/repo') 
(Ken Taylor) #3

That might work for publishToMaven() but not publishToMavenLocal(). I guess its semantics but most organizations don’t want to be publishing to mavenCentral by accident. Right?

(uklance) #4

If you look at the publishing docs you’ll see that

  1. Gradle creates a publish${pubName}PublicationTo${repoName}Repository task for each publication/repo
  2. publishToMavenLocal depends on all of the publishPubNamePublicationToMavenLocal tasks

So it seems that a quick fix is to give your repo the name “mavenLocal”


repositories {
   maven {
      name = 'mavenLocal'
      url = file('/path/to/repo') 

If the publish tasks aren’t autowired into publishToMavenLocal then you can do that yourself

task.all {
    if ( =~ 'publish.*PublicationToMavenLocalRepository') {
        publishToMavenLocal.dependsOn it
(Ken Taylor) #5

Thanks Lance. That does work. I just thought the publishToMavenLocal should work according to the docs, which it no longer does. The publishing plugin skips steps 1 - 3 and goes right to step 4, from the steps listed in the docs I mentioned above.

Now I have to figure out how to replace the hashing algorithms that publishing uses. MD5 and SHA1 are very deprecated.

(uklance) #6

You said

We’ve set the maven.repo.local env var in the shell

but the docs say

The value of system property ‘maven.repo.local’ if set

Have you tried setting “maven.repo.local” system property? (not env variable)


gradle -Dmaven.repo.local=/path/to/repo publishToMavenLocal

Also, have you considered that perhaps ~ is referring to a different location than you expect for the Gradle daemon process?

You could try

task printMvnHome {
   doLast {
      println file('~/.m2').absolutePath