对于多个春季启动项目,Gradle Build失败

时间:2016-11-28 22:23:43

标签: gradle spring-boot multi-project

我正在通过gradle(3.2)多项目挖掘春季启动1.4.2.RELEASE on MACos Sierra 10.12.1。

这是github上的项目: https://github.com/isian8814/demospring.git

这是我的项目结构:

Root project 'demospring'
+--- Project ':model'
\--- Project ':rest'

这是root项目的build.gradle:

buildscript {
    ext.springBootVersion = '1.4.2.RELEASE'

    repositories {
        mavenCentral()
    }

    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
    }
}

allprojects {
    group 'com.springboot.demo'
    version '1.0-SNAPSHOT'
}

subprojects {
    apply plugin: 'java'
    apply plugin: 'org.springframework.boot'

    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    compileJava.options.encoding = 'UTF-8'

    dependencies {
        testCompile('org.springframework.boot:spring-boot-starter-test')
    }

    springBoot {
        mainClass = 'bookmarks.Application'
    }

    repositories {
        mavenCentral()
    }
}

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

这是rest项目的build.gradle:

dependencies {
    compile project(':model')
    compile('org.springframework.boot:spring-boot-starter-web')
}

这是模型项目的build.gradle:

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-web')
    runtime('com.h2database:h2')
}

这是我的settings.gradle:

rootProject.name='demospring'

include 'model'
include 'rest'

我可以运行./gradlew:model:build和./gradlew:rest:build

./gradlew :rest:build
:model:compileJava UP-TO-DATE
:model:processResources UP-TO-DATE
:model:classes UP-TO-DATE
:model:jar
:rest:compileJava
:rest:processResources UP-TO-DATE
:rest:classes
:rest:findMainClass
:rest:jar
:rest:bootRepackage
:rest:assemble
:rest:compileTestJava
Note: /Users/minchanglong/Documents/SourceTree/demospring/rest/src/test/java/bookmarks/BookmarkRestControllerTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:rest:processTestResources UP-TO-DATE
:rest:testClasses
:rest:test
2016-11-29 09:20:36.426  INFO 1692 --- [       Thread-5] o.s.w.c.s.GenericWebApplicationContext   : Closing org.springframework.web.context.support.GenericWebApplicationContext@68250d: startup date [Tue Nov 29 09:20:32 EST 2016]; root of context hierarchy
2016-11-29 09:20:36.429  INFO 1692 --- [       Thread-5] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2016-11-29 09:20:36.429  INFO 1692 --- [       Thread-5] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
2016-11-29 09:20:36.432  INFO 1692 --- [       Thread-5] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
:rest:check
:rest:build

BUILD SUCCESSFUL

Total time: 22.215 secs

但是我无法运行./gradlew clean build

这是错误:

./gradlew clean build
:model:clean
:rest:clean
:model:compileJava
:model:processResources UP-TO-DATE
:model:classes
:model:findMainClass
:model:jar
:model:bootRepackage
:model:assemble
:model:compileTestJava UP-TO-DATE
:model:processTestResources UP-TO-DATE
:model:testClasses UP-TO-DATE
:model:test UP-TO-DATE
:model:check UP-TO-DATE
:model:build
:rest:compileJava
/Users/minchanglong/Documents/SourceTree/demospring/rest/src/main/java/bookmarks/Application.java:19: error: cannot find symbol
        CommandLineRunner init(AccountRepository accountRepository,
                               ^
  symbol:   class AccountRepository
  location: class Application
/Users/minchanglong/Documents/SourceTree/demospring/rest/src/main/java/bookmarks/Application.java:20: error: cannot find symbol
                        BookmarkRepository bookmarkRepository) {
                        ^
  symbol:   class BookmarkRepository
  location: class Application
/Users/minchanglong/Documents/SourceTree/demospring/rest/src/main/java/bookmarks/BookmarkRestController.java:38: error: cannot find symbol
        private final BookmarkRepository bookmarkRepository;
                      ^
  symbol:   class BookmarkRepository
  location: class BookmarkRestController
/Users/minchanglong/Documents/SourceTree/demospring/rest/src/main/java/bookmarks/BookmarkRestController.java:40: error: cannot find symbol
        private final AccountRepository accountRepository;
                      ^
  symbol:   class AccountRepository
  location: class BookmarkRestController
/Users/minchanglong/Documents/SourceTree/demospring/rest/src/main/java/bookmarks/BookmarkRestController.java:43: error: cannot find symbol
        BookmarkRestController(BookmarkRepository bookmarkRepository,
                               ^
  symbol:   class BookmarkRepository
  location: class BookmarkRestController
/Users/minchanglong/Documents/SourceTree/demospring/rest/src/main/java/bookmarks/BookmarkRestController.java:44: error: cannot find symbol
                                                   AccountRepository accountRepository) {
                                                   ^
  symbol:   class AccountRepository
  location: class BookmarkRestController
/Users/minchanglong/Documents/SourceTree/demospring/rest/src/main/java/bookmarks/BookmarkRestController.java:50: error: cannot find symbol
        Collection<Bookmark> readBookmarks(@PathVariable String userId) {
                   ^
  symbol:   class Bookmark
  location: class BookmarkRestController
/Users/minchanglong/Documents/SourceTree/demospring/rest/src/main/java/bookmarks/BookmarkRestController.java:56: error: cannot find symbol
        ResponseEntity<?> add(@PathVariable String userId, @RequestBody Bookmark input) {
                                                                        ^
  symbol:   class Bookmark
  location: class BookmarkRestController
/Users/minchanglong/Documents/SourceTree/demospring/rest/src/main/java/bookmarks/BookmarkRestController.java:76: error: cannot find symbol
        Bookmark readBookmark(@PathVariable String userId, @PathVariable Long bookmarkId) {
        ^
  symbol:   class Bookmark
  location: class BookmarkRestController
/Users/minchanglong/Documents/SourceTree/demospring/rest/src/main/java/bookmarks/Application.java:25: error: cannot find symbol
                                                        Account account = accountRepository.save(new Account(a,
                                                        ^
  symbol:   class Account
  location: class Application
/Users/minchanglong/Documents/SourceTree/demospring/rest/src/main/java/bookmarks/Application.java:25: error: cannot find symbol
                                                        Account account = accountRepository.save(new Account(a,
                                                                                                     ^
  symbol:   class Account
  location: class Application
/Users/minchanglong/Documents/SourceTree/demospring/rest/src/main/java/bookmarks/Application.java:27: error: cannot find symbol
                                                        bookmarkRepository.save(new Bookmark(account,
                                                                                    ^
  symbol:   class Bookmark
  location: class Application
/Users/minchanglong/Documents/SourceTree/demospring/rest/src/main/java/bookmarks/Application.java:29: error: cannot find symbol
                                                        bookmarkRepository.save(new Bookmark(account,
                                                                                    ^
  symbol:   class Bookmark
  location: class Application
/Users/minchanglong/Documents/SourceTree/demospring/rest/src/main/java/bookmarks/BookmarkRestController.java:62: error: cannot find symbol
                                        Bookmark result = bookmarkRepository.save(new Bookmark(account,
                                        ^
  symbol:   class Bookmark
  location: class BookmarkRestController
/Users/minchanglong/Documents/SourceTree/demospring/rest/src/main/java/bookmarks/BookmarkRestController.java:62: error: cannot find symbol
                                        Bookmark result = bookmarkRepository.save(new Bookmark(account,
                                                                                      ^
  symbol:   class Bookmark
  location: class BookmarkRestController
15 errors
:rest:compileJava FAILED

FAILURE: Build failed with an exception.

*** What went wrong:
Execution failed for task ':rest: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.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':rest:compileJava'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:84)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:55)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:61)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
        at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:45)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:233)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:74)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:55)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:113)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
        at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
        at org.gradle.initialization.DefaultGradleLauncher$4.run(DefaultGradleLauncher.java:197)
        at org.gradle.internal.Factories$1.create(Factories.java:25)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:53)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:194)
        at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:36)
        at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:118)
        at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:112)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:63)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:112)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:98)
        at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:66)
        at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
        at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
        at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44)
        at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29)
        at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
        at org.gradle.util.Swapper.swap(Swapper.java:38)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
        at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
        at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:293)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
        at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details.
        at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:48)
        at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:33)
        at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:104)
        at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:53)
        at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:38)
        at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:35)
        at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25)
        at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:188)
        at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:169)
        at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:112)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:163)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
        at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:123)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:95)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:76)
        ... 69 more


BUILD FAILED

Total time: 1.576 secs

有什么想法吗?

感谢。

1 个答案:

答案 0 :(得分:0)

我认为休息项目也应该有dependencies部分,而不是restdependencies

正如@Stanislav所提到的,你应该在根目录中有settings.gradle个文件包含这个内容:

include 'module'
include 'rest'
include 'demospring'

如果您有兴趣,这是我的Github repository with working Spring Boot multimodule project

BTW,该repo还具有所有子模块的测试覆盖率聚合。 Here is blog post belonging to that repository