I stumbled upon one article about how to make fat jar files in Gradle.
jar {
from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
My questions are
what is the jar element? Is it a way to declare properties. As I understand, I can define properties as follows:
prop1{ prop2{ prop3.prop4=5 } }
which is equivalent to: prop1.prop2.prop3.prop4=5
I also found an article about ConfigurationContainer: https://gradle.org/docs/current/javadoc/org/gradle/api/artifacts/ConfigurationContainer.html.
However, I can't link the information to make a full picture here.
A “configuration” is a named grouping of dependencies. A Gradle build can have zero or more of them. A “repository” is a source of dependencies. Dependencies are often declared via identifying attributes, and given these attributes, Gradle knows how to find a dependency in a repository.
Use the command ./gradlew test to run all tests.
runtimeClasspath' contains the compiled classes of the source set, and task autowiring automatically adds the necessary task dependencies. Maybe you want 'sourceSets. main. compileClasspath'.
To get an overview of all Gradle tasks in our project, we need to run the tasks task. Since Gradle 5.1, we can use the --group option followed by a group name. Gradle will then show all tasks belonging to the group and not the other tasks in the project.
jar
is a task name. It has nothing to do with properties. Tasks are the basic building block of every Gradle build. It is equivalent to tasks.jar
from
is a method of the CopySpec
class. Many tasks extend from the CopySpec
class and inherit the from
method.
configurations.compile
is a reference to the all of the artifacts defined in the compile
configuration.
.collect {}
is a method call with one argument that is a closure. {}
is an empty closure.
{ it.isDirectory() ? it : zipTree(it) }
is the closure (aka function) that returns a collection of files to be include in the JAR. it
is the default argument of every closure that in the case, will be a JAR artifact instance from configurations.compile
or a local file path instance. It could be a file path because configurations
support both JARS and local files system paths of compiled .class
files.
The logic in the closure is in the form of <conditional> ? <A> : <B>
and means if <conditional> then return <A> else return <B>
.
The conditional it.isDirectory()
evaluates to True
if the it
variable is a directory. So if it
is a directory we return it
. If it's not a directory, then the code assumes it's a JAR.
zipTree(it)
is a method that extracts all the files from a JAR and returns them as a collection.
All of the file (directories or exploded JARS) are returned from the closure and then "combined" by collect
into a single collection (e.g. FileTree
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With