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 gradle.properties 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?
repositories {
maven {
url = file('/path/to/repo')
}
}
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?
If you look at the publishing docs you’ll see that
- Gradle creates a
publish${pubName}PublicationTo${repoName}Repository
task for each publication/repo -
publishToMavenLocal
depends on all of thepublishPubNamePublicationToMavenLocal
tasks
So it seems that a quick fix is to give your repo the name “mavenLocal”
Eg:
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 (it.name =~ 'publish.*PublicationToMavenLocalRepository') {
publishToMavenLocal.dependsOn it
}
}
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.
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)
Eg
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
}
}