Assume a subproject which declares a dynamic version dependency:
dependencies {
implementation "org.examble:foo-lib:[1.0.0, 1.0.999]"
}
within the root project, I have a javadocAll
task, which aggregates the javadoc of all subprojects. Here I want to link to foo-lib’s javadoc:
javadoc {
…
options {
links = [
"https://example.org/foo-lib/releases/$fooLibStaticVersion/javadoc/"
]
}
}
I experimented a bit a got
def getResolvedVersion(queriedProject = ':my-subproject', component) {
def configuration = project(queriedProject)
.configurations
.compileClasspath
configuration.resolve()
def artifact = configuration
.resolvedConfiguration
.resolvedArtifacts
.find {
// 'it' is of type ResolvedArtifact, 'id' of
// Component*Artifcat*Identifier, and we check the
// ComponentIdentifier.
it.id.getComponentIdentifier() instanceof org.gradle.api.artifacts.component.ModuleComponentIdentifier
&& it.id.getComponentIdentifier().toString().startsWith(component + ':')
}
artifact.getModuleVersion().getId().getVersion()
}
But artifact
is (often?) null
, even though the configuration is in state RESOLVED
. I guess this is because the subproject was not yet in its configuration phase when getResolvedVersion()
was invoked (which is, I assume, during the root projects configuration phase).
getResolvedVersion
was based on the answer provided by my related SO question