Sorting of the Gradle classpath container


(Vadim Lotarev) #1

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,
Vadim


(Stefan Oehme) #2

Hi Vadim,

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

Cheers,
Stefan


(Vadim Lotarev) #3

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?

Regards,
Vadim


(Stefan Oehme) #4

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


(Vadim Lotarev) #5

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


(Stefan Oehme) #6

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.


(Vadim Lotarev) #7

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.


(Stefan Oehme) #8

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


(Jorge Mikitiuk) #9

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