Yet another classpath ordering question

The subject of classpath ordering has been discussed multiple times in this forum, but I still can’t figure out (1) how it is ordered and (2) how to change it.

My environment is multi-project eclipse. We are evaluating gradle to build the deployed version of the app. However, the team primarily compiles, runs and tests the app locally in eclipse, i.e., we use the bin directory, not the build directory. The build directory will be for the CI/CD pipeline.

I have a base project (Proj1) which depends on an older version of a jar (jar-old.jar). I have a second project (Proj2) which depends on Proj1 and depends on a more recent version of the jar (jar-new.jar). I know how to configure gradle to perform the build task correctly, i.e., exclude the older jar in Proj2. The build directory is fine.

The problem is that in eclipse, declaring a project dependency order determines both the source and jar order. (This is true whether or not the eclipse project exports its jars.) In Gradle, no matter what order we use in the dependencies declaration, project dependencies come before jar dependencies. So Proj2 depending on Proj1 means that jar-old.jar comes before jar-new.jar in the runtime classpath for the eclipse launchers.

Gradle does not respect the ordering of its own dependencies declaration. What is the ordering? Alphabetical?

I am not aware of any way to tell eclipse to handle source and jar ordering differently. So my only option is to make project dependencies come last. Using gradle I must move the classpathentry elements for projects after the classpathentry elements for jars in the eclipse .classpath file.

And yes, I appreciate that other developers will have the opposite need sometimes. For them, project dependencies first will be the correct approach.

Simply put, users need to be able to specify the classpath ordering in gradle,

Another thread provides the “solution” to my particular problem. But seriously, I can’t defend this hack to my review team. The order of dependency declaration in a gradle file needs to matter.

1 Like