[JAVA] How to install Gradle and Kotlin with SDKMAN (Mac)

What is "SDKMAN"?

A type of SDK management tool. It is convenient because you can easily switch versions in various SDKs such as Kotlin and Gradle.

environment

Installing SDKMAN

Execute the following command to install.

$ curl -s "https://get.sdkman.io" | bash
$ source "~/.sdkman/bin/sdkman-init.sh"

Gradle installation

#Display a list of Gradle versions that can be installed with SDKMAN
$ sdk list gradle

================================================================================
Available Gradle Versions
================================================================================
     4.7-rc-1             4.4                  3.5.1                2.3
     4.6-rc-2             4.3.1                3.5                  2.2.1
     4.6-rc-1             4.3-rc-4             3.4.1                2.2
     4.6                  4.3-rc-3             3.4                  2.14.1
     4.5.1                4.3-rc-2             3.3                  2.14
     4.5-rc-2             4.3-rc-1             3.2.1                2.13
     4.5-rc-1             4.3                  3.2                  2.12
     4.5                  4.2.1                3.1                  2.11
     4.4.1                4.2-rc-2             3.0                  2.10
     4.4-rc-6             4.2-rc-1             2.9                  2.1
     4.4-rc-5             4.2                  2.8                  2.0
     4.4-rc-4             4.1                  2.7                  1.9
     4.4-rc-3             4.0.2                2.6                  1.8
     4.4-rc-2             4.0.1                2.5                  1.7
     4.4-rc-1             4.0                  2.4                  1.6

================================================================================
+ - local version
* - installed
> - currently in use
================================================================================

#I don't know which version is better, so install without specifying the version
$ sdk install gradle 

# 4.6 is installed, but there is a warning
$ gradle --version
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/Users/{username}/.sdkman/candidates/gradle/4.6/lib/groovy-all-2.4.12.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

------------------------------------------------------------
Gradle 4.6
------------------------------------------------------------

Build time:   2018-02-28 13:36:36 UTC
Revision:     8fa6ce7945b640e6168488e4417f9bb96e4ab46c

Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM:          9.0.4 (Oracle Corporation 9.0.4+11)
OS:           Mac OS X 10.13.1 x86_64

When I checked the warning output when gradle --version, it seems to be an error that occurs when using JDK 9. https://github.com/gradle/gradle/issues/3118

I heard that you should use JDK 8, so this time I will do so.

$ jenv global oracle64-1.8.0.162

$ gradle --version

------------------------------------------------------------
Gradle 4.6
------------------------------------------------------------

Build time:   2018-02-28 13:36:36 UTC
Revision:     8fa6ce7945b640e6168488e4417f9bb96e4ab46c

Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM:          1.8.0_162 (Oracle Corporation 25.162-b12)
OS:           Mac OS X 10.13.1 x86_64

The warning is no longer output.

Install Kotlin

Install it in the same way as Gradle.

$ sdk list kotlin

================================================================================
Available Kotlin Versions
================================================================================
     1.2.31               1.1.2-5              1.0.4
     1.2.30               1.1.2-2              1.0.3
     1.2.21               1.1.2                1.0.2
     1.2.20               1.1.1                1.0.1-2
     1.2.10               1.1-beta2            1.0.1-1
     1.2.0                1.1-beta             1.0.1
     1.1.61               1.1-RC               1.0.0
     1.1.60               1.1-M04
     1.1.51               1.1-M02
     1.1.50               1.1-M01
     1.1.4-3              1.1
     1.1.4-2              1.0.7
     1.1.4                1.0.6
     1.1.3-2              1.0.5-2
     1.1.3                1.0.5

================================================================================
+ - local version
* - installed
> - currently in use
================================================================================

$ sdk install kotlin

$ sdk list kotlin

================================================================================
Available Kotlin Versions
================================================================================
 > * 1.2.31               1.1.2-5              1.0.4
     1.2.30               1.1.2-2              1.0.3
     1.2.21               1.1.2                1.0.2
     1.2.20               1.1.1                1.0.1-2
     1.2.10               1.1-beta2            1.0.1-1
     1.2.0                1.1-beta             1.0.1
     1.1.61               1.1-RC               1.0.0
     1.1.60               1.1-M04
     1.1.51               1.1-M02
     1.1.50               1.1-M01
     1.1.4-3              1.1
     1.1.4-2              1.0.7
     1.1.4                1.0.6
     1.1.3-2              1.0.5-2
     1.1.3                1.0.5

================================================================================
+ - local version
* - installed
> - currently in use
================================================================================

Select SDK to use by default

You can install multiple versions of each SDK. Use the sdk default command to select the SDK to use by default.

# sdk default {SDK} {version}
$ sdk default kotlin 1.2.31

List of SDKs in use

A list of SDKs used by the sdk current command is output.

$ sdk current

Using:

gradle: 4.6
kotlin: 1.2.31

in conclusion

I was able to install Gradle and Kotlin. Now you should be able to develop Android apps.

(2018/04/05 23:30 postscript)

Since it was written in .bash_profile, I edited it to work even in an environment where SDKMAN is not installed.

.bash_profile


#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
- export SDKMAN_DIR="/Users/{username}/.sdkman"
- [[ -s "/Users/{username}/.sdkman/bin/sdkman-init.sh" ]] && source "/Users/{username}/.sdkman/bin/sdkman-init.sh"
+ export SDKMAN_DIR="$HOME/.sdkman"
+ if [ -d "${SDKMAN_DIR}" ]; then
+   [[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"
+ fi

Reference link

Recommended Posts

How to install Gradle and Kotlin with SDKMAN (Mac)
How to install JDK8-10 (Mac)
How to install Eclipse (Photon) on Mac
How to create a server executable JAR and WAR with Spring gradle
How to set up and operate jEnv (Mac)
How to build API with GraphQL and Rails
How to use nginx-ingress-controller with Docker for Mac
Install gradle on mac
Install Gradle with ubuntu16.04
How to install Docker
How to install docker-machine
How to install MySQL
How to use Gradle
How to install ngrok
How to install & import Auto Gluon with Google Colaboratory
How to build docker environment with Gradle for intelliJ
How to serialize and deserialize LocalDateTime type with GSON
I want to transition screens with kotlin and java!
How to make Laravel faster with Docker for Mac
How to use RealSense with ubuntu 20.04 and ROS Noetic
Common problems with WSL and how to deal with them
[Kotlin] How to get IP address and user agent
How to uninstall Java 8 (Mac)
Gradle to touch and remember
[Rails] How to install devise
How to install Boots Faces
How to number (number) with html.erb
How to update with activerecord-import
[Rails] How to install simple_calendar
[Rails] How to install reCAPTCHA
How to decompile apk file to java source code with MAC
How to use trained model of tensorflow2.0 with Kotlin / Java
How to transform ARKit and SceneKit shapes with Metal shader
How to Install Elixir and Phoenix Framework on Ubuntu 20.04 LTS
How to use mysql with M1 mac Docker preview version
I want to implement various functions with kotlin and java!
How to install PHP 7.4 and SQL Server drivers in CentOS 7.7
How to deal with different versions of rbenv and Ruby
How to scroll horizontally with ScrollView
How to use StringBurrer and Arrays.toString.
[Rails] How to install Font Awesome
How to use \ t Escape sequences different for mac and Windows-java
How to install and use Composer on an ECS instance on Ubuntu 16.04
How to get started with slim
Install Java and Tomcat with Ansible
How to use EventBus3 and ThreadMode
How to run Ant in Gradle
How to install ImageMagick on Windows 10
I want to return to the previous screen with kotlin and java!
[How to install Spring Data Jpa]
[Webpacker] Summary of how to install Bootstrap and jQuery in Rails 6.0
[Rails] How to introduce kaminari with Slim and change the design
I can't install lombok with Gradle.
Hello world with Kotlin and JavaFX
How to call classes and methods
mysql2 fails to install with bundle install
[Tips] How to solve problems with XCode and Swift for beginners
How to switch Java version with direnv in terminal on Mac
How to install Bootstrap in Ruby
How to install and configure the monitoring tool "Graphite" on Ubuntu
How to install Pry after building Rails development environment with Docker