My project has a dependency on a previous version of it’s own published artifact on Maven (for compatibility analysis at build time), but this dependency cannot be resolved. As a result, the “old” artifact is never downloaded from Maven repository.
Note: This ONLY happens, when publication’s artifactId and project’s name are the same.
Minimal example:
Gradle version: 5.6.4 (I cannot yet migrate to 6.x)
settings.gradle:
rootProject.name = "project-name"
build.gradle:
plugins {
id 'maven-publish'
}
version = '2.0'
group = 'com.example'
repositories {
mavenLocal()
}
configurations {
previous
}
dependencies {
previous 'com.example:project-name:1.0'
}
publishing {
publications {
maven(MavenPublication) {
version = '1.0'
}
}
}
Tasks to execute:
gradle publishToMavenLocal dependencies
Although the older version is published in the local repository, the dependency could not be resolved.
If I change the project name before running the “dependencies” task (for example to “project-name2”), the dependency is resolved normally.
“dependency” task output:
previous
\--- com.example:project-name:1.0 FAILED
Is this the expected behavior? Are there maybe any workarounds available, as some of the project names I cannot change anymore?
Thank you.
Edit:
If I explicitly set the target configuration is dependency declaration, the dependency is resolved, but is considered a “current” project and not an external dependency (from repository):
previous group: "com.example", name: "project-name", version: "1.0", configuration: "previous"
“dependencies” task output:
previous
+--- com.example:project-name:1.0 -> project : (*)
(*) - dependencies omitted (listed previously)