###前提・実現したいこと
java, spring boot 2, gradleで下記のようなappがcommonを参照する構成のマルチプロジェクトを作成しています。
IntelliJ IDEA のエディタ上では特に警告はありませんが、gradle build
時にエラーが発生します。
解消方法をご教示ください。
├─ app │ ├─ src/main/java │ │ ├─ com.example.app.AppApplication │ │ └─ com.example.app.controller.AppController │ ├─ build.gradle │ └─ settings.gradle ├─ common │ ├─ src/main/java │ │ └─ com.example.common.service.CommonService │ └─ build.gradle │ ...
###発生している問題・エラーメッセージ
$ gradle build > Task :compileJava FAILED /dummy/app/src/main/java/com/example/app/controller/AppController.java:3: エラー: パッケージcom.example.common.serviceは存在しません import com.example.common.service.CommonService; ^ /dummy/app/src/main/java/com/example/app/controller/AppController.java:8: エラー: シンボルを見つけられません private CommonService commonService; ^ シンボル: クラス CommonService 場所: クラス AppController /dummy/app/src/main/java/com/example/app/controller/AppController.java:10: エラー: シンボルを見つけられません public AppController(CommonService commonService) { ^ シンボル: クラス CommonService 場所: クラス AppController エラー3個 FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':compileJava'. > Compilation failed; see the compiler error output for details. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 3s 2 actionable tasks: 2 executed
###該当のソースコード
app
- src/main/java/com/example/app/AppApplication
java
1package com.example.app; 2 3import org.springframework.boot.SpringApplication; 4import org.springframework.boot.autoconfigure.SpringBootApplication; 5import org.springframework.context.annotation.ComponentScan; 6 7@SpringBootApplication 8@ComponentScan("com.example.common") 9public class AppApplication { 10 11 public static void main(String[] args) { 12 SpringApplication.run(AppApplication.class, args); 13 } 14}
- src/main/java/com/example/app/controller/AppController
java
1package com.example.app.controller; 2 3import com.example.common.service.CommonService; 4import org.springframework.stereotype.Controller; 5 6@Controller 7public class AppController { 8 private CommonService commonService; 9 10 public AppController(CommonService commonService) { 11 this.commonService = commonService; 12 } 13}
- build.gradle
gradle
1buildscript { 2 ext { 3 springBootVersion = '2.0.0.M7' 4 } 5 repositories { 6 mavenCentral() 7 maven { url "https://repo.spring.io/snapshot" } 8 maven { url "https://repo.spring.io/milestone" } 9 } 10 dependencies { 11 classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 12 } 13} 14 15allprojects { 16 apply plugin: 'java' 17 apply plugin: 'eclipse' 18 apply plugin: 'org.springframework.boot' 19 apply plugin: 'io.spring.dependency-management' 20 21 group = 'com.example' 22 version = '0.0.1-SNAPSHOT' 23 sourceCompatibility = 1.8 24 25 repositories { 26 mavenCentral() 27 maven { url "https://repo.spring.io/snapshot" } 28 maven { url "https://repo.spring.io/milestone" } 29 } 30 31 dependencies { 32 compile('org.springframework.boot:spring-boot-starter-web') 33 testCompile('org.springframework.boot:spring-boot-starter-test') 34 } 35} 36 37dependencies { 38 compile project(':common') 39}
- settings.gradle
gradle
1rootProject.name = 'app' 2 3includeFlat 'common' 4project(':common').projectDir = new File('../common')
common
- src/main/java/com/example/common/service/CommonService
java
1package com.example.common.service; 2 3import org.springframework.stereotype.Service; 4 5@Service 6public class CommonService { 7}
- build.gradle
gradle
1(empty)
あなたの回答
tips
プレビュー