A little troublesome story in Groovy

the first

The other day, [here](http://stackoverflow.com/questions/9577929/cleanest-way-in-gradle-to-get-the-path-to-a-jar-file-in-the-gradle-dependency- I was watching ca). I needed a list of JARs to collect all the dependent JARs and automatically combine them into one JAR. I saw the code here and thought.

prologue.groovy


project.configurations.compile*.each{...}

If so, I wonder if it is possible to get the JAR path by iterative processing. Now, let's copy and execute the following code into the build.gradle of the Module.

prologue2.groovy


project.configurations.compile*.each{
    println it
}

Do you think you can see the list of paths?

No

The contents of the JAR file (as if all the JARs were cated) are output to the standard output. The console (Terminal) was very rough and it was hard.

Solution and conclusion

So what should I do?

correct.groovy


project.configurations.compile*.toURI().each {
    File file=new File(it)
    println file//Replace it with a process that uses a File object.
}

It is like this. Change it to ʻURIand then back toFile. This will ensure that File` can be handled iteratively. So why did you output the contents of the JAR file to standard output? This is just a guess,

  1. Comes with a List (maybe) containing a File object
  2. Read the ** all lines ** of that File (File.readLines () ) and make it ʻArrayList`.
    I didn't write it above, but I think it was such a result.
  3. Expand ʻArrayList that stores all the rows and ʻeach. If all this is println, it will be rough ...

Recommended Posts

A little troublesome story in Groovy
A little regular expression story Part 1
A little addictive story with def initialize
A story about the JDK in the Java 11 era
A troublesome story when deleting the gems file created in the gem development directory.
A story about BeanNotOfRequiredTypeException occurring after applying AOP in Spring
A story I was addicted to in Rails validation settings
Multiplication in a Ruby array
Find a subset in Java
A little complicated conditional branching
A story stuck with NotSerializableException
A funny story stuck in a mess when trying to import fx-clj
The story that Tomcat suffered from a timeout error in Eclipse
A little addictive story after updating the JDBC driver for PostgreSQL
A story stuck with log output in Docker + Play framework environment