# Android + maven-publish versionMapping

**URL:** <https://discuss.gradle.org/t/android-maven-publish-versionmapping/46371>\
**Category:** Help/Discuss\
**Created:** [August 29, 2023, 8:26am UTC](https://discuss.gradle.org/t/android-maven-publish-versionmapping/46371 "2023-08-29T08:26:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maragues](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/maragues/32/9009_2.png) [@Maragues](https://discuss.gradle.org/u/Maragues)\
**Post date:** [August 29, 2023, 8:26am UTC](https://discuss.gradle.org/t/android-maven-publish-versionmapping/46371/1 "2023-08-29T08:26:33Z")

</div>

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.

```groovy
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](https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:resolved_dependencies)

I’ve tried two approaches

```plaintext
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)

```plaintext
versionMapping {
    allVariants {
        fromResolutionResult()
    }
}

```

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

---

<div class="post-metadata">

**Author:** ![Maragues](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/maragues/32/9009_2.png) [@Maragues](https://discuss.gradle.org/u/Maragues)\
**Post date:** [August 29, 2023, 3:21pm UTC](https://discuss.gradle.org/t/android-maven-publish-versionmapping/46371/2 "2023-08-29T15:21:29Z")

</div>

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?
