home wiki.fukuchiharuki.me
Menu

Gradleをインストールする

Gradleを設定する

cd multiproject
gradle init

サブプロジェクトを定義する

  • settings.gradle
rootProject.name = 'multiproject'
include 'domain'
include 'persistence'
include 'web'

依存関係を定義する

  • build.gradle

次を想定しています。

  • 依存関係
    • domain
    • persistence -> domain
    • web -> domain
    • web -> persistence
  • domainはLombokしか使わない
  • persistenceはMyBatisでMySQLに接続する
  • webはThymeleafを使う
buildscript {
	ext {
		springBootVersion = '1.5.1.RELEASE'
	}
	repositories {
		mavenCentral()
	}
	dependencies {
		classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
	}
}

subprojects {
	apply plugin: 'java'
	apply plugin: 'eclipse'
	sourceCompatibility = 1.8
	repositories {
		mavenCentral()
	}
	dependencies {
		compileOnly "org.projectlombok:lombok:1.16.12"
	}
}

project(':domain') {
}

project(':persistence') {
	dependencies {
		compile project(':domain')
		compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.2.0')
	}
}

project(':web') {
	apply plugin: 'org.springframework.boot'
	jar {
		baseName = 'demo'
		version = '0.0.1-SNAPSHOT'
	}
	dependencies {
		compile project(':domain')
		compile project(':persistence')
		compile('org.springframework.boot:spring-boot-starter-web')
		compile('org.springframework.boot:spring-boot-starter-thymeleaf')
		runtime('mysql:mysql-connector-java')
		testCompile('org.springframework.boot:spring-boot-starter-test')
	}
}

途中。