Android + maven-publish versionMapping

Hi, I’m using dependencySubstitution on my android projects. When a property is present and the dependency meets some conditions, then I add -SNAPSHOT suffix to the version.

if (properties["useCodegenSnapshot"] == "true") {
    configurations.configureEach {
        resolutionStrategy.dependencySubstitution.all { DependencySubstitution dependency ->
            def requestedDependency = dependency.requested
            if (requestedDependency instanceof ModuleComponentSelector
                    && requestedDependency.group == "com.my.company"
                    && !requestedDependency.version.endsWith("-SNAPSHOT")
            ) {
                def snapshotVersion = "${requestedDependency.version}-SNAPSHOT"
                useTarget("${requestedDependency.group}:${requestedDependency.module}:$snapshotVersion")
            }
        }
    }
}

This works fine when building locally: It resolves snapshot versions.

The issue comes when I publish a library to maven: The published .pom ignores the dependencySubstitution.

I try to configure maven-publish plugin to apply a fromResolutionResult, as instructed in publishing_maven:resolved_dependencies

I’ve tried two approaches

project.configure<PublishingExtension> {
            publications {
                create(publicationName, MavenPublication::class) {
                    groupId = publisherPluginExtension.groupId
                    artifactId = publisherPluginExtension.artifactId
                    version = publisherPluginExtension.getArtifactoryVersionName()

                    versionMapping {
                        usage("java-api") {
                            fromResolutionOf("releaseRuntimeClasspath") //I can't use fromResolutionOf('runtimeClasspath') because runtimeClasspath doesn't exist on android
                        }
                        usage("java-runtime") {
                            fromResolutionResult()
                        }
                    }
                }
            }

And another approach, where I configure all variants (omitting the rest of the configuration)

versionMapping {
    allVariants {
        fromResolutionResult()
    }
}

But the published .pom never adds the -SNAPSHOT suffix to the version of internal packages.

I think my issues come from the fact that I use includeBuild, which can take its own DependencySubstitutions Action.

I’ve checked resolving the dependency inside usage("java-runtime") { and the result is that com.my.company:module:version is replaced by project :project-name:module. It completely ignores the resolutionStrategy of the host project.

Am I on the right path?