Is it possible to use one of the current project publication in a different version

My java project publish a custom file as a java variant. This file is an openapi specification.

I would like to ensure this file is backward compatible with the previously published specification. To achive this goal I created a “backwardChecker” task. But when i tried to add the configuration on the previous version of the project, the current specification is always used.

Here is a simplified version of my build.gradle.kts

plugins {
  id("java-library")
  id("maven-publish")
}

group = "com.vgalloy.gradle-self-include"
version = "0.0.2-SNAPSHOT"

val openApiConfiguration = configurations.create("openApiConfiguration") {
  isVisible = false
  isCanBeConsumed = true
  isCanBeResolved = false
  attributes.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named("openapi-spec"))
}

val generateSpec = tasks.register("generateSpec") {
  outputs.file("$buildDir/my-spec.json")
  doLast {
    File("$buildDir/my-spec.json").writeText("""{"name":"My spec"}""")
  }
}
openApiConfiguration.outgoing.artifact(generateSpec) {
  classifier = "openapi-spec"
}

(components["java"]as AdhocComponentWithVariants).addVariantsFromConfiguration(openApiConfiguration) {}

publishing {
  publications {
    create<MavenPublication>("maven") {
      from(components["java"])
    }
  }
}

repositories {
  mavenLocal()
}

val resolvableConfig = configurations.create("resolvableConfig"){
  isVisible = false
  isCanBeConsumed = false
  isCanBeResolved = true
  attributes.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named("openapi-spec"))
}

dependencies {
  resolvableConfig("$group:${project.name}:0.0.1") // do not forget to change the current version and run ./gradlew publishToMavenLocal to publish the artifact
}

val checkFileDoNotChange = tasks.register("checkFileDoNotChange") {
  inputs.property("conf", resolvableConfig)
  doLast {
    resolvableConfig.resolve().forEach {
      println("Perform check with $it")
    }
  }
}

Running ./gradlew checkFileDoNotChange will print

Perform check with  [...]build/my-spec.json

Instead of using the 0.0.1 version. Is it the normal behaviour ? Did i miss something ?

Note 1: I noticed the same behaviour with jar. We can not use another version of the current project

dependencies {
  api("$group:${project.name}:$anotherVersion") // will fail
}

Note 2: seems I can achive my goal by creating a new AdhocComponent and publish it with a different (groupId-artifactId). But I’m not sure that the write way to achive my goal