Dependency with packaging=pom is not resolved transitively

(Matt Khan) #1

I am upgrading a particular build from 2.14.1 to 4.4

It has a dependency which has packaging=pom and which is used to pull in a few other dependencies as a bundle. This is resolved as expected in 2.14.1 (i.e. you get the transitive dependencies) but this behaviour changes in 4.4 in 2 ways.

Firstly I have to explicitly say that the dependency is of type pom (as in ‘’) otherwise the build fails because there is no jar for this dependency.

Secondly, once I’ve made this change, I do not get the transitive dependencies. It appears this is because org.gradle.api.internal.artifacts.dsl.dependencies.ModuleFactoryHelperdoes the following

public class ModuleFactoryHelper {
	public static void addExplicitArtifactsIfDefined(ExternalDependency moduleDependency, String artifactType, String classifier) {
		String actualArtifactType = artifactType;
		if (actualArtifactType == null) {
			if (classifier != null) {
				actualArtifactType = DependencyArtifact.DEFAULT_TYPE;
		} else {
		if (actualArtifactType != null) {
			moduleDependency.addArtifact(new DefaultDependencyArtifact(moduleDependency.getName(),
					actualArtifactType, actualArtifactType, classifier, null));

I can workaround this by passing setting transitive = true via a configuration closure after creating the dependency but it seems odd.

What is the rationale for this behaviour?
Is there another, correct, way to express this dependency in gradle?

(Chris Doré) #2

I don’t have a solution for you, but I share your concern. I have projects that generate and consume pom-only modules and this sounds like an issue I will also run into if I try upgrading from Gradle 2.3.

This part is not new behaviour. “Artifact-only” dependencies have (always?) defaulted to non-transitive in the past.

(Matt Khan) #3

it resolved them transitively in 2.14.1 so it is definitely a change

(Chris Doré) #4

Do you have an example that reproduces this handy? They are not resolved transitively in my project, using 2.3.