mavenLocal() headaches

Hey folks, I’ve been struggling with this for a bit now.

I have a Gradle project that depends on a maven artifact. If the artifact exists in a remote repository, all is well. However, if I make changes to the maven project and install locally, Gradle won’t find it - doesn’t matter if it’s a SNAPSHOT version or not.

I’ve blown away my gradle caches without any change.

Moved the mavenLocal() reference to be the first and last repository (other articles I found suggested it should be last).

I’ve reviewed my M2_HOME/conf/settings.xml - no configuration there.

I’ve tried referencing my local maven repo via an explicit url vs using mavenLocal.

I’m out of ideas. Any ideas from you guys?

Hi, since Gradle 6.0 artifact resolution rules have changed a bit. The Gradle module is favored over the pom unless configured otherwise. But the Gradle module is not deployed in the maven local repository with the maven-publish plugin. To restore the usual artifact resolution, instead of writing:

repositories {
    mavenLocal()
}

write:

repositories {
    mavenLocal {
        metadataSources {
            mavenPom()
            artifact()
        }
    }
}

Link to the relevant API: MavenArtifactRepository (Gradle API 6.8.2)

Thanks, however, I had tried this previously (forgot to mention it). Just did it again for safe measure, but no change in behavior (included clearing existing .grade caches).

Any other ideas?

This is not true. A .module file is published alongside the POM and artifacts when using the publishToMavenLocal task.

Just to make sure, use this task to confirm that the url used by mavenLocal() makes sense and does indeed match maven’s install path:

task dumpRepos {
    doLast {
        println repositories.collect { it.url }.join( '\n' )
    }
}

What does your dependency declaration in Gradle look like?

Thanks for following up. I’m don’t see the content displayed from the dumpRepos task (using --debug).

Here is the relevant section for the build:

   buildscript {
    repositories {
        gradlePluginPortal()
        jcenter()
        maven { url "https://dl.bintray.com/micronaut/core-releases-local" }
        maven { url "https://repo.grails.org/grails/core" }
        mavenLocal {
          metadataSources {
            mavenPom()
            artifact()
          }
       }
    }
    dependencies {
        classpath "io.micronaut.build:micronaut-gradle-plugins:2.0.15"
    }

Do you expect the micronaut-gradle-plugins to be served by the repositories you declared above it?
Because if that is the case, it cannot work.
In buildscript { repositories { ... } } you declare repositories for build script dependencies declared in buildscript { dependencies { ... } }.
In top-level repositories { ... } or for all build scripts centrally in the settings script in dependencyResolutionManagement { repositories { ... } } you declare repositories where project dependencies like your micronaut-gradle-plugins are resolved from.

1 Like

Indeed, thanks for pointing that error.
I have a bunch of initialization scripts and in one of them I disable Gradle Module Metadata publication. I tried on a fresh home dir and the module is effectively published.