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.