LoginSignup
4
4

More than 5 years have passed since last update.

GradleのインストールからHello World!まで。[CentOS 6]

Last updated at Posted at 2016-07-09

GradleをCentOS6.x上にインストールする手順をまとめます。

手順

JDKをインストールします。

今回は、java-1.8.0のversionをインストールします。

[vagrant@localhost ~]$ yum install -y java-1.8.0-openjdk-devel

***省略***

Complete!

# version確認
[vagrant@localhost ~]$ java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
[vagrant@localhost ~]$
gradle.zipの最新版を落としてきます。

今現在では、gradle-2.14が最新versionです。--no-check-certificateオプションをつけないと「安全の確認をしないで接続するには、`--no-check-certificate' を使ってください。」と言われることがあるので気をつけて下さい。

# zipファイルを落としてきます。
[vagrant@localhost ~]$ wget https://services.gradle.org/distributions/gradle-2.14-all.zip --no-check-certificate

***省略***

# /opt/gradle配下に解凍します。
[vagrant@localhost ~]$ unzip gradle-2.14-all.zip -d /opt/gradle
環境変数の設定

下記のように環境変数を設定してください。

.bash_profile
export GRADLE_HOME=/opt/gradle/gradle-2.14
export PATH=$GRADLE_HOME/bin:$PATH
# sourceコマンドで展開します。
[vagrant@localhost ~]$ source .bash_profile

# versionを確認します。
[vagrant@localhost ~]$ gradle -v

------------------------------------------------------------
Gradle 2.14
------------------------------------------------------------

Build time:   2016-06-14 07:16:37 UTC
Revision:     cba5fea19f1e0c6a00cc904828a6ec4e11739abc

Groovy:       2.4.4
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_91 (Oracle Corporation 25.91-b14)
OS:           Linux 2.6.32-431.el6.x86_64 amd64
ビルドスクリプトの作成

では簡単に「Hellp World!」と出力するスクリプトを書いていきます。
gradleは、Groovyで書かれていて、デフォルトのファイル名は「build.gradle」となっているのでその通りにファイルを作成します。

build.gradle
task hello << {
  println 'Hello World!'
}
[vagrant@localhost ~]$ gradle hello
:hello
Hello World! # Hello World!と出力されています。

BUILD SUCCESSFUL

Total time: 3.753 secs

This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.14/userguide/gradle_daemon.html
[vagrant@localhost ~]$


# gradle tasksとするとタスク一覧を出してくれます。
[vagrant@localhost ~]$ gradle tasks
:tasks

------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

***省略***

Other tasks
-----------
hello // 作成されたタスク

To see all tasks and more detail, run gradle tasks --all
To see more detail about a task, run gradle help --task <task>

BUILD SUCCESSFUL

Total time: 4.357 secs

This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.14/userguide/gradle_daemon.html
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4