2017-03-11 26 views
1

だから私はgradleとspring-bootを使って(実験的に)演奏しています。サブモジュールを使ってSpringブートを設定する方法

私がこんにちはの世界に従うと、私は簡単にプロジェクトの実行を手に入れることができます。

私は構造化プロジェクトを作りたいと思います。このため私はIntellijコミュニティを使用しています(関連性があるかどうかはわかりません)。私は次の構造を持っています。

/プロジェクト - build.gradle - settings.gradle(サービスのみを含む) /プロジェクト/サービス/ - build.gradle - settings.gradle(のみたMyServiceを含む) /プロジェクト/サービス/ MyServices - build.gradle

私はbuild.gradleファイルのいくつかを共有することができますが、私はインターネット上で見つけたランダムなものを試しています。私の問題は、MyServiceで春のブートクラスを利用できないことです。 Myserviceの内部は標準のJava(/ src/main/java)です

可能であれば、私の主なbuild.gradleに依存関係&のバージョンを入れようとしています。誰かが私が間違っていることを指摘できますか?

現在、私は単純なアンドロイドの開発作業にgradleを使用しました。

/Project/build.gradle

group 'nl.msegers.project' 
version '1.0-SNAPSHOT' 

apply plugin: 'java' 
apply plugin: 'idea' 

sourceCompatibility = 1.8 

repositories { 
    mavenCentral() 
} 

dependencies { 
    testCompile group: 'junit', name: 'junit', version: '4.11' 
} 

/Project/Services/build.gradle

group 'nl.msegers.project.services' 

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE") 
    } 
} 

/Project/Services/MyService/build.gradle

group 'nl.msegers.project.services.myservice' 
version parent.version 

apply plugin: 'java' 
apply plugin: 'idea' 
apply plugin: 'org.springframework.boot' 

jar { 
    baseName = 'Navigation' 
    version = parent.version 
} 

repositories { 
    mavenCentral() 
} 

sourceCompatibility = 1.8 
targetCompatibility = 1.8 

答えて

0

私はこのような構造を得るために1時間ほどウェブを精練しています。その間、私はプロジェクトを最初から再構築しました(とにかくコードはあまりありませんでしたが)。

私のコードでは、あまりにも多くの冗長構成をせずに単純なSpringブートのサブプロジェクトを許可していますが、かなり簡単にライブラリプロジェクトをコンパイルすることができます。

私が今得たのは、このような構造です。

/プロジェクト /プロジェクト/ライブラリ /プロジェクト/ライブラリ/モデル /プロジェクト/サービス/ /プロジェクト/サービス/サービス

のみ顕著なビルドで。Gradleのファイル(他の人がほぼ空になっている):

/プロジェクト/サービス/

group 'nl.msegers.project.services' 
version parent.version 

buildscript { 
    ext { 
     springBootVersion = "1.5.2.RELEASE" 
    } 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
    } 
} 

subprojects { 
    buildscript { 
     ext { 
      springBootVersion = "1.5.2.RELEASE" 
     } 
     repositories { 
      mavenCentral() 
     } 
     dependencies { 
      classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
     } 
    } 
    apply plugin: 'java' 
    apply plugin: 'org.springframework.boot' 


    dependencies { 

     compile("org.springframework.boot:spring-boot-starter-web") { 
      exclude module: "spring-boot-starter-tomcat" 
     } 
     compile("org.springframework.boot:spring-boot-starter-jetty") 
     compile("org.springframework.boot:spring-boot-starter-actuator") 

     compile project(':Libraries:Models') 

     testCompile 'junit:junit:4.12' 
    } 

    task wrapper(type: Wrapper) { 
     gradleVersion = '3.1' 
    } 
} 

/プロジェクト/サービス/ MyServiceで

group 'nl.msegers.project.services.myservice' 
version parent.version 

jar { 
    baseName = 'myservice' 
    version = parent.version 
} 

repositories { 
    mavenCentral() 
} 
1

へすべてのプロジェクトがルートからの依存関係を継承するようにするには、あなたのルートプロジェクトの好きな場所にallprojectsスクリプトブロックを使用できますe:

allprojects { 
      dependencies { 
     compile group: 'commons-collections', name: 'commons-collections', version: '3.+' 
     ... 
    } 
} 
+0

また、これは、サブ・プロジェクトのために働くのだろうか? 私の問題は、同じレベルのビルド.gradleで定義すると依存関係が読み込まれないということです。 –

+0

この問題は、springboot用に1つの場所にビルドスクリプトを定義し、別の場所にプラグインを適用したためです。https://docs.gradle.org/current/userguide/plugins.html#sec:applying_plugins_buildscript – Adonis

+0

あなたの答えは正しい方向に私を置きます。少し違って解決しました。また、自分のサービスに含まれている/ Libraries/Modulesプロジェクトを持っています。私は今日どこかでやったこととは別の答えを作ります。 –

関連する問題