0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Gradle】Springbootのプロジェクトを作る際に調べた依存ライブラリについて

Posted at

Gradleとは

「Apache AntやApache Mavenのコンセプトに基づくオープンソースビルド自動化システム」
参考: Gradle入門 - Qiita

SpringbootのプロジェクトでGradleを使った為、躓いた内容のについて記述。

ざっくりとGradleとは必要なファイルを作ってビルド作業を行うと、プロジェクトに必要なファイルやソースを自動的に組み立ててくれるツール。

依存ライブラリについて

Gradleのビルドは、gradleコマンドで実行して。そのgradleコマンドはカレントディレクトリのbuild.gradleファイルを参照してビルドを行ってくれる。
build.gradleファイルにはざっくりとSpringプロジェクトで使うためのライブラリを使う為に宣言する場所がある。
依存関係はdependenciesブロック内で定義することができる。

Gradle依存関係の書き方について

build.gradle
dependencyManagement { 
    dependencies { 
        compile group:'org.springframework', name:'spring-core', version:'4.0.3.RELEASE' 
    } 
}

また、下記の様にショートカット形式を使うこともできる。

build.gradle
dependencyManagement { 
    dependencies { 
        compile 'org.springframework:spring-core:4.0.3.RELEASE' 
    } 
}

どちらの構文でも、この構成により、すべての依存関係(直接または推移的)spring-coreがバージョンを持てる。(compileコンフィグレーションは孫以降の依存関係にも伝播する為、今は推奨されていないみたいです。)

今回躓いた所

依存ライブラリの内容があまりわからず調査するのに苦労した為、箇条書きで下記に記述。

implementation 'org.springframework.boot:spring-boot-starter-web'

Web アプリを作る場合は、 spring-boot-starter-web モジュールを使用する。
Spring MVCを使用してRESTfulアプリケーションを含むWebを構築するためのスターター。

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

Spring Data JPAを使用するためのスターター。SpringではDBにJPAを利用するがこれはSpringbootからJPAを利用するための機能を提供する。DBを利用するなら必須

implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation "org.thymeleaf:thymeleaf-spring4:3.0.11.RELEASE"
implementation "org.thymeleaf:thymeleaf:3.0.11.RELEASE"

テンプレートエンジンの設定
Thymeleafビューを使えるMVC Webアプリケーションを構築するためのスターター
下2行はspring-boot-starter-thymeleafのツリー下にあるのだが、バージョンを変更する必要があったので記述。

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

自動リソース管理、getter、setter、equals、hashCodeおよびtoStringの自動生成してくれる。

developmentOnly 'org.springframework.boot:spring-boot-devtools'

クラスパス変更時に自動再起動してくれる(ホットリロード機能)
デフォルトでは、変更を保存すると、Eclipseでこれが自動的に行われる。

runtimeOnly 'com.h2database:h2'

組み込みとしてもサーバとしても使えるJava製のデータベーH2のライブラリ

implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter'

MyBatisのためのスターター

annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'

注釈が付けられたアイテムから独自の構成メタデータファイルを簡単に生成できる(Gradle 4.6以降ではannotationProcessorと宣言する)

]providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'

Tomcatを組み込みサーブレットコンテナーとして使用するためのスターター。
spring-boot-starter-webによって使用されるデフォルトのスターターサーブレットコンテナ


testImplementation('org.springframework.boot:spring-boot-starter-test') {
	//JUnit4以前のグループを除外
	exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}

JUnit、Hamcrest、Mockitoなどのライブラリを使用してSpring Bootアプリケーションをテストするためのスターター

各ライブラリのバージョン設定についてはGradleコマンド「gradle dependencies」で依存ツリーを確認しながらライブラリの宣言を行って下さい。
今後、修正箇所があれば適宜更新します。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?