build.gradle has the following dependencies -
dependencies {
compile("com.rhuldip.artifactId:com.rhuldip.mainDependency:1.0.0-SNAPSHOT")
}
In my maven repository, I have the following files at location REPO_URL/com/rhuldip/artifactId/com.rhuldip.mainDependency/1.0.0-SNAPSHOT
- maven-metadata.XML
- com.rhuldip.mainDependency-1.0.0.pom
- com.rhuldip.mainDependency-1.0.0.jar
The file com.rhuldip.mainDependency-1.0.0.pom contains transitive dependency and a variable like this -
<properties>
<myapp.version>${revision}</myapp.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.rhuldip.myapp</groupId>
<artifactId>transitiveDependeny</artifactId>
<version>${myapp.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
But I am getting this error -
***
01:08:40 > Could not resolve com.rhuldip.artifactId:com.rhuldip.mainDependency:1.0.0-SNAPSHOT.
01:08:40 > Could not parse POM REPO-URL/com/rhuldip/artifactId/com.rhuldip.mainDependency/1.0.0-SNAPSHOT/com.rhuldip.mainDependency-1.0.0-SNAPSHOT.pom
01:08:40 > Could not find com.rhuldip.myapp:transitiveDependeny:${revision}.
I am using gradle 4.10.2 version. I tried sending a revision variable like this but still getting the same error
ext {
revision: '1.1.0-SNAPSHOT'
}
I suppose you have:
You need to explicitly define the
revisionproperty in your Gradle build script so that it can be properly resolved when fetching the transitive dependency.But: Gradle 4.10.2 (2018!) does not automatically pass properties defined in the
extblock to the Maven POM resolver. You can try instead defining this property at the top level of your build script.A resolution strategy to substitute the variable in the transitive dependency version could help... even in 4.10.2.
Use the
ResolutionStrategyin yourbuild.gradlefile to dynamically replace the version of the transitive dependency.Implement the strategy to replace the dynamic version (
${revision}) with a specific version fortransitiveDependeny.Your
build.gradlefile would be:That configuration in your
build.gradletells Gradle to replace the${revision}placeholder in the version oftransitiveDependenywith the specific version1.1.0-SNAPSHOT.As an alternative workaround, you can explicitly declare the transitive dependency in your
build.gradlefile with the correct version. That way, Gradle will not rely on the POM file to resolve the version. And modify yourbuild.gradleto include the transitive dependency with a specific version.That approach essentially bypasses the issue by not relying on the Maven POM file to resolve the dynamic version of
transitiveDependeny. Instead, you are directly specifying the dependency and its version in your Gradle project.So the transitive dependency is hosted in a remote Maven repository. That means the repository configuration in your Gradle project must correctly point to this remote repository.
And the problem is that the version of the transitive dependency is specified as a variable (
${revision}) in the POM file ofcom.rhuldip.artifactId:com.rhuldip.mainDependency.Make sure your
build.gradleincludes the remote Maven repository wherecom.rhuldip.myappis located:Since the resolution strategy to replace the
${revision}placeholder does not work as expected, try and explicitly declare the transitive dependency with a fixed version, as previously mentioned. That is a more direct approach and can sometimes bypass issues with variable resolution in POM files.Define the
revisionvariable in agradle.propertiesfile, which might be more effective in some setups.Your
build.gradlewould be:And the
gradle.propertiesfile:But make sure the version
1.1.0-SNAPSHOTofcom.rhuldip.myapp:transitiveDependencyis indeed available in the remote repository. If it is not, replace this with the correct available version.