Deterministic ordering of dependencies on the classpath

(Martin Vehovský) #1


coming from maven world you are actually able to control classpath order as of version 2.0.9 maven uses pom order for classpath so you can manipulate it freely and it has proven very useful in the past for us.

From what I read (and I may be wrong) Gradle doesn’t give any guarantees about the classpath ordering.

Can someone point me to the right direction how to implement similar behavior as Maven provides? Meaning preserves the ordering inside dependencies block. Even if it means writing a plugin or whatever.


(Mark Vieira) #2

This isn’t necessary. The order inside the dependencies { } block is preserved.

(Martin Vehovský) #3

You are kind of right. Dependency ordering is preserved, but for example all compile dependencies will be before testCompile dependencies no matter of how you order them.

(Mark Vieira) #4

Depending on the nature of your conflict you could also exclude the dependency from ‘testCompile’ rather than force the correct one higher on the classpath.

(Martin Vehovský) #5

Yes basically that is what we eventually… prepending specific dependencies as discussed in other topics on the forum.

(Nikos Viorres) #6

Hi there,

I have noticed that if you add the dependency programmatically, i.e. project.dependencies.add(‘compile’, ‘’) order is not preserved.

Not only that but although it evaluates to the same thing across invocations, it’s not the same on different machines. Do you have any ideas / recommendations how to deal with this apart from sorting the compileClasspath and setting it explicitly on each compile task?

The reason i have to do the programmatic dependency addition is that i am migrating a very old build that uses maven2 + ant still and in order to keep exactly the same resolution rules while migration is in progress i still read dependencies from pom (via ant-maven plugin) and set them to gradle not as files but gradle managed ones to be able to pull sources etc.