What is Gradle?

I was interested in the java build, so a memo at that time.

What is Gradle

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.

Gradle initialization

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

Dependency resolution

gradle manages packages outside of java and makes them available for your own projects.

dependencies {
    implemention("package name")
}

task

The task in gradle is, quoted from the official, the detailed work to do the build.

Built-in tasks

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.

Task definition

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.

Configure a task with actions

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.

gradle tips

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.

Parallelization

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

Profiling

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.

screenshot-scans.gradle.com-2020.03.20-12_00_39.png

This profiling is pretty handy and can give you important information for building efficiency, such as heavy testing and suggestions.

reference

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/

Finally

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

What is Gradle?
What is Cubby
What is null? ]
What is java
What is Keycloak
What is maven?
What is Jackson?
What is self
What is Jenkins
What is ArgumentMatcher?
What is IM-Juggling?
What is params
What is SLF4J?
What is Facade? ??
What is Java <>?
What is POJO
What is Java
What is centOS
What is RubyGem?
What is programming?
What is before_action?
What is Docker
What is Byte?
What is Tomcat
What is Maven Assembly?
What is `docker-compose up`?
What is a constructor?
What is vue cli
What is an interface?
What is Ruby's self?
What is hard coding?
What is a stream
What is Ruby's attr_accessor?
What is Java Encapsulation?
What is permission denied?
What is an initializer?
What is Spring Tools 4
What is an operator?
What is object orientation?
What is Guava's @VisibleForTesting?
What is MVC model?
What is an annotation?
What is Java technology?
What is Java API-java
What is @ (instance variable)?
What is Gradle's Artifact?
What is JPA Auditing?
[Swift] What is dismiss?
[Java] What is flatMap?
What is a Servlet?
What is web development?
[Java] What is JavaBeans?
[Android] What is Context? ??
[Java] What is ArrayList?
[Ruby] What is true?
What is object-oriented after all?
What is HttpSession session = request.getSession ();
What is docker run -it?
What is Java Assertion? Summary.
[Memorandum] What is an error?
What is DI (Dependency Injection)