How do I control the order of compile classpaths?

I encountered the same problem as documented here: http://issues.gradle.org/browse/GRADLE-1512. 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)

1 Like

bump Has anyone looked at this?

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.

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.