Gradleプラグインspring-boot-dependencies
とspring-boot
を使用するマルチモジュールプロジェクトでは、正しいGradle設定はどのようになりますか?マルチモジュールのGradle依存プラグインSpringブートプロジェクト
私は次のプロジェクトを設定している:
parent
|
+ build.gradle
|
+ alpha
| |
| + build.gradle
|
+ beta
| |
| + build.gradle
parent
モジュールは、一般的なプロジェクト構成が含まれています。alpha
モジュールは、spring-boot-dependencies bomに指定されたバージョン番号を使用して依存関係をインポートするモジュールですが、その結果は標準のjarです。beta
モジュールはalpha
に依存するモジュールであり、結果は実行可能なSpringブートjarファイル(すべての依存関係を含む)です。したがって、このプロジェクトにはspring-boot-dependencies
とspring-boot
プラグインの両方が必要です。
GradleファイルDRYを保持するために、私は共通のモジュールスクリプトを親のbuild.gradle
ファイルに抽出しました。親が
allprojects {
group = "com.example"
version '0.0.1-SNAPSHOT'
ext {
dependencyManagementPluginVersion = '0.5.3.RELEASE'
springBootVersion = '1.3.0.RC1'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
}
subprojects {
sourceCompatibility = 1.8
targetCompatibility = 1.8
buildscript {
repositories {
jcenter()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("io.spring.gradle:dependency-management-plugin:${dependencyManagementPluginVersion}")
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
// mavenBom("org.springframework.boot:spring-boot-starter-parent:${springBootVersion}")
}
}
}
アルファgradle.build
> Plugin with id 'io.spring.dependency-management' not found.
:に結果以下プロジェクト構成を使用して$ gradle build
を実行する
試み件の
ベータgradle.build
apply plugin: 'spring-boot'
dependencies {
compile project(':alpha')
compile('org.springframework.boot:spring-boot-starter')
compile('org.springframework.boot:spring-boot-starter-web')
}
コメント:
- 春ブーツで
spring-boot
プラグインwas changedの行動1.3.0.M1 - Gradleのバージョン:2.8
- 春ブートバージョン1.3.0.RC1
私の答えが役に立ちましたら、アップしてください。 – Opal
@Opal遅れて申し訳ありませんが、私はあなたの答えを受け入れたと思いました。私は[ブログ投稿](http://www.jayway。com/2015/11/23/reusing-spring-boots-dependency-management /)については、謝辞を確認してください。 :-) – matsev
ありがとう、ちょうど私が持っていた問題---他の人がこの問題を拾い読みするのを助けるために、私は追加します:あなたが素朴に試してみると:あなたのサブプロジェクトにプラグイン 'spring-boot' -management for free)あなたはビルドエラー(少なくとも私はウィンドウの下にあります)を得ます: タスク ':xxxxx:bootRepackage'の実行に失敗しました。 'xxxxx.jar'の名前を 'xxxxx.jar.original'に変更できません – Rop