Not able to find Snapshot from Gradle plugin

Hello Gradle community,

I recently upgraded my project from Gradle 8.2 to 8.4, and I’m facing an issue with consuming snapshot dependencies from my Maven repository, where I have a Gradle plugin published. Everything was working fine with Gradle 8.2, but after the upgrade, I’m unable to resolve snapshot dependencies. Release publications do work though.

For better understanding, I’m trying to publish both the snapshots and release repositories in a local folder on my local machine.

I can consume the release publications without any issues, but not the snapshot ones.

In the project where I have hosted the Gradle plugin, I have a Gradle script called my-script.kts, with a content similar to the following one:

plugins {
    `maven-publish`
}

afterEvaluate {
    publishing {
        publications {
            named<MavenPublication>("pluginMaven") {
                groupId = project.properties[groupIdKey].toString()
                artifactId = project.properties[artifactIdKey].toString()
                version = version(project.properties[versionNameKey].toString())
            }
        }

        repositories {
            // Release Repository Definition
            maven {
                name = "release"
                url = uri("path-to-my-local-folder")
            }
            // Snapshot Repository Definition
            maven {
                name = "snapshot"
                url = uri("path-to-my-local-folder")
            }
        }
    }
}

Then, in the build.gradle of my Gradle plugin, I have:

plugins {
    `java-gradle-plugin`
    id(Kotlin.jvm)
    `kotlin-dsl`
    id("my-script")
}

version = version(project.properties[versionNameKey].toString())
group = project.properties[groupIdKey].toString()

gradlePlugin {
    plugins {
        create("myArtifactId") {
            id = "mydomain.myArtifactId"
            implementationClass = "com.mydomain.myClass"
        }
    }
}

Here’s the output after running the task

./gradlew publishAllPublicationsToSnapshotRepository

            ├── myArtifactId
                │   ├── 2.0.0-alpha-5558-SNAPSHOT
                │   │   ├── myArtifactId-2.0.0-alpha-5558-20240619.084912-1.jar
                │   │   ├── myArtifactId-2.0.0-alpha-5558-20240619.084912-1.jar.md5
                │   │   ├── myArtifactId-2.0.0-alpha-5558-20240619.084912-1.jar.sha1
                │   │   ├── myArtifactId-2.0.0-alpha-5558-20240619.084912-1.jar.sha256
                │   │   ├── myArtifactId-2.0.0-alpha-5558-20240619.084912-1.jar.sha512
                │   │   ├── myArtifactId-2.0.0-alpha-5558-20240619.084912-1.module
                │   │   ├── myArtifactId-2.0.0-alpha-5558-20240619.084912-1.module.md5
                │   │   ├── myArtifactId-2.0.0-alpha-5558-20240619.084912-1.module.sha1
                │   │   ├── myArtifactId-2.0.0-alpha-5558-20240619.084912-1.module.sha256
                │   │   ├── myArtifactId-2.0.0-alpha-5558-20240619.084912-1.module.sha512
                │   │   ├── myArtifactId-2.0.0-alpha-5558-20240619.084912-1.pom
                │   │   ├── myArtifactId-2.0.0-alpha-5558-20240619.084912-1.pom.md5
                │   │   ├── myArtifactId-2.0.0-alpha-5558-20240619.084912-1.pom.sha1
                │   │   ├── myArtifactId-2.0.0-alpha-5558-20240619.084912-1.pom.sha256
                │   │   ├── myArtifactId-2.0.0-alpha-5558-20240619.084912-1.pom.sha512
                │   │   ├── maven-metadata.xml
                │   │   ├── maven-metadata.xml.md5
                │   │   ├── maven-metadata.xml.sha1
                │   │   ├── maven-metadata.xml.sha256
                │   │   └── maven-metadata.xml.sha512
                │   ├── mydomain.myArtifactId.gradle.plugin
                │   │   ├── 2.0.0-alpha-5558-SNAPSHOT
                │   │   │   ├── mydomain.myArtifactId.gradle.plugin-2.0.0-alpha-5558-20240619.084912-1.pom
                │   │   │   ├── mydomain.myArtifactId.gradle.plugin-2.0.0-alpha-5558-20240619.084912-1.pom.md5
                │   │   │   ├── mydomain.myArtifactId.gradle.plugin-2.0.0-alpha-5558-20240619.084912-1.pom.sha1
                │   │   │   ├── mydomain.myArtifactId.gradle.plugin-2.0.0-alpha-5558-20240619.084912-1.pom.sha256
                │   │   │   ├── mydomain.myArtifactId.gradle.plugin-2.0.0-alpha-5558-20240619.084912-1.pom.sha512
                │   │   │   ├── maven-metadata.xml
                │   │   │   ├── maven-metadata.xml.md5
                │   │   │   ├── maven-metadata.xml.sha1
                │   │   │   ├── maven-metadata.xml.sha256
                │   │   │   └── maven-metadata.xml.sha512
                │   │   ├── maven-metadata.xml
                │   │   ├── maven-metadata.xml.md5
                │   │   ├── maven-metadata.xml.sha1
                │   │   ├── maven-metadata.xml.sha256
                │   │   └── maven-metadata.xml.sha512
                │   ├── maven-metadata.xml
                │   ├── maven-metadata.xml.md5
                │   ├── maven-metadata.xml.sha1
                │   ├── maven-metadata.xml.sha256
                │   └── maven-metadata.xml.sha512

From the build.gradle of the project where I’m consuming the plugin I’m using:

plugins {
    id("mydomain.myArtifactId") version "2.0.0-alpha-5558-SNAPSHOT"
}

But when I’m trying to consume the plugin in another project I get the following error:

  • Exception is:
    org.gradle.api.plugins.UnknownPluginException: Plugin [id: ‘mydomain.myArtifactId’, version: ‘2.0.0-alpha-5558-SNAPSHOT’] was not found in any of the following sources:

And between the sources there are of course the release and snapshot repository i.e.,

maven(file:/path-to-my-local-folder/snapshot)
maven2(file:/path-to-my-local-folder/release)

I would appreciate any guidance or suggestions on resolving this issue with consuming snapshot dependencies after upgrading to Gradle 8.4, since I’ve been reviewing the release notes from 8.3 and 8.4 and saw nothing relevant to this that could be affecting.

Have you tried to “consume” the snapshot plugin like that:

plugins {
id(“mydomain.myArtifactId”) version “2.0.0-SNAPSHOT”
}
In general the automatically generated suffix stamp (like alpha-5558 etc) is for repository/artifactory-side only management. In the client(build script) it should not be used.

Sorry, I think missed that “alpha-5558” is a part of your version label. So it will not resolve your issue.
Anyway it is worth testing the snapshot publishing and consuming with standard Maven artifact versioning :

<major version>.<minor version>.<incremental version>-<qualifier>

Might be an error in what you wrote here, but from what you showed you configured the same path path-to-my-local-folder for snapshot and releases repository (which thus does not really make much sense as you can just use on of them, but on the consuming side have path-to-my-local-folder/snapshot and path-to-my-local-folder/release, where then of course nothing is found.

If it indeed was an error in what you posted here and you also deploy do different locations (your listing starts deeper in the hierarchy so it is unclear), do you maybe have used for example

mavenContent {
    releasesOnly()
}

for your plugin repositories?

Thanks for helping.

It’s only when I use the -SNAPSHOT suffix that Gradle adds the timestamp, otherwise it won’t treat it as a snapshot, but as a release and it will be able to resolve the dependency.

I tried to use the standard Maven artifact versioning as you suggested

<major version>.<minor version>.<incremental version>-<qualifier>

So, I kept the -SNAPSHOT qualifier having a version name like 2.0.0-SNAPSHOT, Gradle added the timestamp and got an output like the following, but it’s not able to resolve it on the consumer side.

  ├── myArtifactId
                │   ├── 2.0.0-SNAPSHOT
                │   │   ├── encryption-2.0.0-20240619.132121-1.jar

I forgot to mention that I’m the project from where I’m generating the plugins I’m using Gradle 8.8 and from the consumer, currently I’m using 8.4. Eventually I tried to use the 8.8 on both sides, but I didn’t work either. Definitely the problem starts when using version 8.4 on the consumer side, therefore when upgrading from 8.3 to 8.4 there’s some difference in the behaviour.

I don’t see why using the same path wouldn’t work. I can tell that even though now I’m trying it locally, I have the same structure in a remote maven repo an it works perfectly fine until Gradle 8.4

To let things clear, here’s a simplified representation of the structure of my local repo (the same structure works with release without any issue). Here I removed my identifier, therefore the version of the artifact is 2.0.0-alpha-SNAPSHOT. And since I’m using the SNAPSHOT suffix, Gradle is adding the timestamp

/Users/myUser/testv1
└── release
   ...
└── snapshot
   └── mydomain
       └── myArtifactId
           │   ├── 2.0.0-alpha-SNAPSHOT
           │   │   ├── myArtifactId-2.0.0-alpha-20240619.125059-1.jar
           │   │   ├── myArtifactId-2.0.0-alpha-20240619.125059-1.jar.md5

A part from that I also added the mavenContent block, but it didn’t work either

mavenContent {
    releasesOnly()
} 

I don’t see why using the same path wouldn’t work.

It would work, if you would use it.
Like you showed it you publish to the same path but consume from different paths.
But as you now showed, you obviously do not publish to the same path but different paths.

I also added the mavenContent block, but it didn’t work either

Of course it does not work with that block, that block says “don’t take snapshots from there, only release versions”. I asked whether you maybe have used that which could have caused it.

1 Like