How do I control the order of compile classpaths?

(aispina) #1

I encountered the same problem as documented here: How ever my situation doesn’t have the same work around. Basically, one of my projects builds a jar that contains classes that need to be loaded instead of certain other classes in a library. This means that my project jar needs to show up before the library jar in the classpath. The behavior that I’ve observed suggests that project jars are always last in the classpath. This prevents my project from building. How should I handle this?

(sorry if cross posting this question is bad form. I wasn’t sure where was best to post)

(aispina) #2

bump Has anyone looked at this?

(Peter Niederwieser) #3

I’m not sure if the dependencies section gives some guarantees on the order of dependencies. I think it should.

In general, you can prepend to a class path like so:

sourceSets.main.compileClasspath = file(“foo.jar”) + sourceSets.main.compileClasspath

Repackaging the third-party Jar is another alternative, and possibly the better solution.

(Adam Murdoch) #4

The only guarantee that the ‘dependencies { }’ section gives is that for a given set of dependencies, the results will be returned in a fixed but arbitrary order. ie for a given set of dependendencies, you’ll always get the same classpath, but you can’t do anything to influence the order. If you really want to mess with the order, you need to write some code to do so, like the above.