Sorting of the Gradle classpath container

Dear team,

I am just wondering whether is it possible to sort entries alphabetically in the Gradle classpath container created by Buildship?

Thanks in advance,

Hi Vadim,

generally this is possible using the eclipse.classpath.file.whenMerged {} hook, but the question is: Why would you like to do that?


Hi Stefan,

Sometimes I want to look at the resolved artifacts when some changes are made in build.gradle. For example, to determine the real resolved version of the artifact with version='latest.release'. Another reason could be to identify the transitive dependencies. I understand that all that tasks can be easily done with gradle dependencies command but sometimes it is convenient just to look quickly inside the classpath container. It would be even more convenient if container is sorted.

Could you please lest me know briefly how to use this hook?


I think it would be better if Buildship provided a dependency view for this, similar to gradle dependencies output, what do you think?

I think that this would be the best solution. But how fast it could be implemented? :slight_smile:

There are no plans at the moment but we are open for contributions. A dependencies view would definitely be a welcome feature.

And of course there is still the workaround you initially asked for, sorting the entries by name in the whenMerged hook.

Talking about that workaround could you please advice what is the right way to use the hook. I tried something like:

eclipse {
    classpath {
        defaultOutputDir = file('classes')
        downloadSources = true
        downloadJavadoc = true

        file.whenMerged { classpath -> classpath.entries.sort() }

but this doesn’t work as expected.

The entries themselves are not comparable, you’ll have to sort by some criterion, e.g. the path.

Hi, I guess is something like this:
file.whenMerged { classpath -> classpath.entries.sort{ it.getKind().equalsIgnoreCase(“lib”) ? it.getPath().substring(it.getPath().lastIndexOf(’/’)) : “” }}