Explanation for configurations.compile.collect { it.getName() }.join(' ')


(matt) #1

Hello everyone,

probably lots of you will find this question annoying and too easy, but it is causing me a bit of a headache.
I needed to compile my java code into an executable jar, and in order to set the classpath attrubute of the manifest i used ‘Class-Path’ : configurations.compile.collect { it.getName() }.join(’ '). It worked perfectly and I get what it does, but since i just discovered that instruction in a forum post I wanted to go to the documentation and find out how people got to that solution but I was able to find out only what a ConfigurationContainer and configurations are.
Now I now that compile is one of the four configurations created by the java plugin, but how can I see all the methods associated to it ?
Thank you for your time and patience.


(Shinya Mochida) #2

Which do you mean?

  1. the list of configurations
  2. the methods of Configuration

If the former is what you want, you can see all configurations via gradle dependencies. If the later, you can find them in javadoc.


(davidmichaelkarr) #3

That’s all true, but the method in his example is one of the cases that confuses people. Technically, you can find the “collect” method in the GDK javadoc for the “Collection” class, and you can see that Configuration is an Iterable, which leads to Collection, but you have to know that Groovy “enhances” Java classes, which is what the GDK javadoc shows. All in all, it’s not trivial to just “get a list of methods”. Even if you could, that would be a long list.


(matt) #4

Thanks for the replies. I was looking in the wrong place. Just took a look at the groovy documentation and now all is well.


(François Guillot) #5

The configurationContainer holds configuration instances, as stated in the ConfigurationContainer DSL page.

Configuration is an interface, because as an end-user you should only be interested by the services offered by such type, and not its implementation, which is the responsibility of the gradle devs.


(matt) #6

That is without doubt correct, I got that far myself going through the gradle documentation. In my opinion knowing how things work and not just copy-paste code is paramount. Collect doesn’t appear anywhere in the gradle docs pages regarding configuration and since I need to use it as an end-user i wanted to know where it came from.

I just started using gradle and this build script required more knowledge of Groovy than I anticipated. A good excuse to get more into it.


(François Guillot) #7

Configuration is a FileCollection which is in turn a Collection
The groovydoc http://docs.groovy-lang.org/latest/html/groovy-jdk/java/util/Collection .html brings you the precious intel


(SGU) #8

Hi, I am also new to Gradle and have exact same question when I try to understand configurations.compile. By tracing down the source code, I can tell Configuration is a FileCollection. But I cannot see why FileCollection is a Collection, I don’t see FileCollection extends Collection in the Javadoc: https://docs.gradle.org/current/javadoc/org/gradle/api/file/FileCollection.html.
Thank you!


(François Guillot) #9

Hi

Well, it comes from Groovy enhancements, in this case on the Object class

François


(SGU) #10

That’s what I missed. Thank you Francois !