Building the development environment of jooby with Eclipse Although it is related to, I would like to be able to build with Gradle.
--Development environment is Windows --Java 8 is already installed on Windows --Eclipse has been set to work with Java 8 --Gradle is already installed in Eclipse
[Here](http://qiita.com/kitaji0306/items/a8deddb194f845a4fbd6#maven%E3%81%A7%E3%83%97%E3%83%AD%E3%82%B8%E3%82%A7% E3% 82% AF% E3% 83% 88% E3% 83% 87% E3% 82% A3% E3% 83% AC% E3% 82% AF% E3% 83% 88% E3% 83% AA% E3% 81% AE% E4% BD% 9C% E6% 88% 90% E3% 81% 93% E3% 81% 93% E3% 81% BE% E3% 81% A7% E3% 81% A7% E3% 82% B5% E3% 83% BC% E3% 83% 90% E5% 86% 85% E3% 81% A7% E3% 81% AE% E4% BD% 9C% E6% A5% AD% E3% 81% AF% Create a project directory by referring to E7% B5% 82% E4% BA% 86). (Implemented to maven archetype)
[vagrant@localhost ~]$ sudo mkdir /opt/gradle
[vagrant@localhost ~]$ sudo wget https://services.gradle.org/distributions/gradle-3.5.1-bin.zip -O /opt/gradle/gradle-3.5.1-bin.zip
--2017-07-18 09:21:40-- https://services.gradle.org/distributions/gradle-3.5.1-bin.zip
Resolving services.gradle.org (services.gradle.org)... 104.16.174.166, 104.16.175.166, 104.16.171.166, ...
Connecting to services.gradle.org (services.gradle.org)|104.16.174.166|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://downloads.gradle.org/distributions/gradle-3.5.1-bin.zip [following]
--2017-07-18 09:21:40-- https://downloads.gradle.org/distributions/gradle-3.5.1-bin.zip
Resolving downloads.gradle.org (downloads.gradle.org)... 104.16.171.166, 104.16.172.166, 104.16.173.166, ...
Connecting to downloads.gradle.org (downloads.gradle.org)|104.16.171.166|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 73302707 (70M) [application/zip]
Saving to: ‘/opt/gradle/gradle-3.5.1-bin.zip’
100%[====================================================================================>] 73,302,707 19.4MB/s in 4.1s
2017-07-18 09:21:44 (17.2 MB/s) - ‘/opt/gradle/gradle-3.5.1-bin.zip’ saved [73302707/73302707]
[vagrant@localhost ~]$ sudo unzip -d /opt/gradle/ /opt/gradle/gradle-3.5.1-bin.zip
Archive: /opt/gradle/gradle-3.5.1-bin.zip
creating: /opt/gradle/gradle-3.5.1/
inflating: /opt/gradle/gradle-3.5.1/LICENSE
~~~
[vagrant@localhost ~]$ cd /vagrant/my-app/
[vagrant@localhost my-app]$ /opt/gradle/gradle-3.5.1/bin/gradle init --type pom
Starting a Gradle Daemon (subsequent builds will be faster)
:wrapper
:init
Maven to Gradle conversion is an incubating feature.
BUILD SUCCESSFUL
Total time: 7.44 secs
build.gradle
[vagrant@localhost my-app]$ cat build.gradle
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
group = 'com.mycompany'
version = '1.0-SNAPSHOT'
description = """my-app"""
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
configurations.all {
}
repositories {
maven { url "http://repo.maven.apache.org/maven2" }
}
dependencies {
compile group: 'org.jooby', name: 'jooby-netty', version:'1.1.3'
compile group: 'ch.qos.logback', name: 'logback-classic', version:'1.1.7'
testCompile group: 'junit', name: 'junit', version:'4.12'
testCompile group: 'io.rest-assured', name: 'rest-assured', version:'3.0.1'
[vagrant@localhost my-app]$ /opt/gradle/gradle-3.5.1/bin/gradle eclipse
:eclipseClasspath
:eclipseJdt
:eclipseProject
:eclipse
BUILD SUCCESSFUL
Total time: 1.68 secs
Refer to jooby's official website and add the necessary settings.
--buildscript block
buildscript {
repositories {
mavenCentral()
}
dependencies {
/** joobyRun */
classpath group: 'org.jooby', name: 'jooby-gradle-plugin', version: '1.1.3'
}
}
apply plugin: 'java'
apply plugin: 'jooby'
group = 'com.mycompany'
version = '1.0-SNAPSHOT'
description = """my-app"""
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
configurations.all {
}
repositories {
maven { url "http://repo.maven.apache.org/maven2" }
}
dependencies {
compile group: 'org.jooby', name: 'jooby-netty', version:'1.1.3'
compile group: 'ch.qos.logback', name: 'logback-classic', version:'1.1.7'
testCompile group: 'junit', name: 'junit', version:'4.12'
testCompile group: 'io.rest-assured', name: 'rest-assured', version:'3.0.1'
}
joobyRun {
mainClassName = 'com.mycompany.App'
}
[2017-07-18 09:50:08,097]-[HotSwap] INFO com.mycompany.App - [dev@netty]: Server started in 1292ms
GET / [*/*] [*/*] (/anonymous)
listening on:
http://localhost:8080/
Hello World!
It seems to be working properly.
It was not reloaded. If you look closely, you will see the following display on the console.
>>> jooby:run[info|Daemon worker]: Hotswap available on: [C:\work\tmp\pleiades\eclipse]
Apparently, the installation path of Eclipse itself has become the base directory. After investigating the source, it seems that the reference directory can be set with a system variable called ** user.dir **. Therefore, define the above variables in the joobyRun task. (Is the path of gradle's root project safe?)
build.gradle
~~~
joobyRun {
mainClassName = 'com.mycompany.App'
System.setProperty("user.dir", rootDir.path)
}
Hello World!
It seems that it is reloaded automatically.
[2017-07-18 12:13:26,477]-[HotswapScanner] INFO com.mycompany.App - Stopped
~~~
[2017-07-18 12:13:27,693]-[HotSwap] INFO com.mycompany.App - [dev@netty]: Server started in 1102ms
GET / [*/*] [*/*] (/anonymous)
listening on:
http://localhost:8080/
Hello World!
that? It was reloaded, but the correction result is not reflected.
As shown below, reloading is detected because the class files viewed by each are different, but the actual reloading result is not reflected. It seems that it was in a situation.
--Eclipse default compilation directory: my-app / bin --Compilation directory normally used by Gradle: build / classes / main --It doesn't matter this time, but the directory that maven normally uses: target / classes
Manually specify the Eclipse compilation directory individually as shown below.
Hello World!
Hello World!!!!!!!!!!!!!!!!!!!
It was reflected. With this, it seems that you can run the development environment with gradle and proceed with the development work.
I have manually changed the classpath settings in Eclipse, so I don't think it's the best way to do it, but is it still acceptable for the first time? (Maybe you can set it well when creating a gradle project with the Eclipse plugin)
Recommended Posts