I was interested in the java build, so a memo at that time.
A jar file with a java build tool (a zip file format of java bytecode files and images) Will build to. Unlike maven, configuration files are written in the language grovy.
Also, make a gradle wrapper so that you don't have to install gradle every time. By distributing this, you can use gradle even in an environment where gradle is not installed.
Create a simple gradle project.
gradle init
This will create various files. Specifically, the following feeling
├── build.gradle
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
gradle manages packages outside of java and makes them available for your own projects.
dependencies {
implemention("package name")
}
The task in gradle is, quoted from the official, the detailed work to do the build.
This task was created several times when the gradle project was generated. For example, test, build, run, etc.
They are,
gradle tasks
You can see the list at.
You can define this yourself, so let's define a simple task.
task hello {
println("hello")
}
Let's run it.
gradle hello
#You should see the following
#hello
#:hello UP-TO-DATE
You can create tasks like this, and internally bundle plugin settings and specific tasks.
A task recognizes the task to be executed in units called actions, and executes it sequentially as an array.
The action is doFirst: add to the beginning doLast: Add to the end
I will add it in the form of.
task hello{
hello.doFirst {
println "hello1"
println "hello2"
}
hello.doLast {
println "hello3"
println "hello4"
}
}
When you do this
gradle hello
Result is
:hello
hello1
hello2
hello3
hello4
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
Will be.
You can customize the processing order by controlling the execution order in this way.
So far, I've roughly touched on how to use gradle, but now I'd like to look at useful functions for setting and analysis that make each task faster.
grale basically only executes tasks one by one. but, There is a setting to force parallel execution. Note that this runs completely independent tasks in parallel, so any dependencies will continue to run sequentially.
Add the following to gradle.properties.
org.gradle.parallel=true
gradle has a function to profile and visualize how much time was spent executing tasks, how much time was executed in parallel, and so on.
If you add --scan
when executing the task, the URL will be displayed in the CLI after execution, and you can check it from there.
However, this requires registration of an email address with gradle, so it is necessary to consider the information management part.
This profiling is pretty handy and can give you important information for building efficiency, such as heavy testing and suggestions.
https://qiita.com/opengl-8080/items/0a192b62ee87d8ac7578#%E3%82%BF%E3%82%B9%E3%82%AF%E3%81%AE%E5%8F%82%E7%85%A7
https://guides.gradle.org/performance/
In gradle, the configuration file is in its own language, but once you get used to that language, the configuration is easy to read and The impression is that you can set tasks in detail.
It's also nice to have yesterday's verification and improvement, including profiling at build time.
Let's have a good gradle life
Recommended Posts