Gradle - 包括其他项目导致错误

时间:2017-09-17 20:57:28

标签: java gradle

我克隆了this github repo,创建了一个新的分支,并希望将该本地项目包含在另一个gradle项目中。

所以,我的文件夹结构是

+- socketcluster-client-java (github project)
+---- build.gradle
+---- settings.gradle

+- Project
+----- build.gradle
+----- settings.gradle

因此,socketcluster-client-java是Project中的依赖项。这是Project

中的settings.gradle文件
rootProject.name = 'Project'

include ':socketcluster-client-java'
project(':socketcluster-client-java').projectDir = new File('/path/to/socketcluster-client-java')

而这就是我在Project

的build.gradle中包含的内容
dependencies {
   compile project(':socketcluster-client-java')
}

但是,当我刷新依赖项(Gradle - >刷新gradle项目)时,我得到了

    org.gradle.tooling.GradleConnectionException: Could not fetch model of type 'EclipseProject' using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.9-bin.zip'.
    at org.gradle.tooling.internal.consumer.ResultHandlerAdapter.onFailure(ResultHandlerAdapter.java:63)
    at org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor$1$1.run(DefaultAsyncConsumerActionExecutor.java:57)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    at org.gradle.tooling.internal.consumer.BlockingResultHandler.getResult(BlockingResultHandler.java:46)
    at org.gradle.tooling.internal.consumer.DefaultModelBuilder.get(DefaultModelBuilder.java:49)
    at com.gradleware.tooling.toolingclient.internal.DefaultToolingClient.executeAndWait(DefaultToolingClient.java:95)
    at com.gradleware.tooling.toolingclient.internal.DefaultModelRequest.executeAndWait(DefaultModelRequest.java:79)
    at com.gradleware.tooling.toolingmodel.repository.internal.DefaultModelRepository$13.get(DefaultModelRepository.java:331)
    at com.gradleware.tooling.toolingmodel.repository.internal.DefaultModelRepository.executeAndWait(DefaultModelRepository.java:420)
    at com.gradleware.tooling.toolingmodel.repository.internal.DefaultModelRepository.access$200(DefaultModelRepository.java:67)
    at com.gradleware.tooling.toolingmodel.repository.internal.DefaultModelRepository$14.call(DefaultModelRepository.java:353)
    at com.google.common.cache.LocalCache$LocalManualCache$1.load(LocalCache.java:4724)
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3522)
    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2315)
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2278)
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2193)
    at com.google.common.cache.LocalCache.get(LocalCache.java:3932)
    at com.google.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4721)
    at com.gradleware.tooling.toolingmodel.repository.internal.DefaultModelRepository.getFromCache(DefaultModelRepository.java:369)
    at com.gradleware.tooling.toolingmodel.repository.internal.DefaultModelRepository.executeRequest(DefaultModelRepository.java:350)
    at com.gradleware.tooling.toolingmodel.repository.internal.DefaultModelRepository.executeRequest(DefaultModelRepository.java:326)
    at com.gradleware.tooling.toolingmodel.repository.internal.DefaultModelRepository.fetchEclipseGradleBuild(DefaultModelRepository.java:226)
    at org.eclipse.buildship.core.workspace.SynchronizeGradleProjectJob.forceReloadEclipseGradleBuild(SynchronizeGradleProjectJob.java:87)
    at org.eclipse.buildship.core.workspace.SynchronizeGradleProjectJob.runToolingApiJobInWorkspace(SynchronizeGradleProjectJob.java:70)
    at org.eclipse.buildship.core.util.progress.ToolingApiWorkspaceJob$1.run(ToolingApiWorkspaceJob.java:74)
    at org.eclipse.buildship.core.util.progress.ToolingApiInvoker.invoke(ToolingApiInvoker.java:54)
    at org.eclipse.buildship.core.util.progress.ToolingApiWorkspaceJob.runInWorkspace(ToolingApiWorkspaceJob.java:71)
    at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:39)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':testRuntime'.
    at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingConfigurationResolver.wrapException(ErrorHandlingConfigurationResolver.java:70)
    at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingConfigurationResolver.resolve(ErrorHandlingConfigurationResolver.java:45)
    at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.resolveGraphIfRequired(DefaultConfiguration.java:367)
    at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.resolveNow(DefaultConfiguration.java:342)
    at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.access

感谢您的帮助!

修改

我可以通过compile group: 'io.github.sac', name: 'SocketclusterClientJava', version: '1.7.2'包含socketcluster-client-java,但我需要使用自己的分支。

EDIT2

我刚用两个模拟项目测试了这种情况,我可以在另一个中包含一个作为依赖而没有任何问题。我现在很困惑

EDIT3

以下例外由Could not resolve all dependencies for configuration ':testRuntime'.

引起

EDIT4

以下是gradle build --refresh-dependencies --info --debug

的日志
    07:33:55.020 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Completing Build operation 'Calculate task graph'
07:33:55.025 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 
07:33:55.026 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
07:33:55.026 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 
07:33:55.026 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
07:33:55.026 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Could not determine the dependencies of task ':compileJava'.
07:33:55.026 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Could not resolve all task dependencies for configuration ':compileClasspath'.
07:33:55.026 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]    > Could not resolve project :socketcluster-client-java.
07:33:55.027 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]      Required by:
07:33:55.028 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]          project :
07:33:55.028 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]       > Unable to find a matching configuration of project :socketcluster-client-java: None of the consumable configurations have attributes.

EDIT5

我创建了一个github project,它在问题描述中扮演Project的角色。当我尝试按照上面描述的方式在Project中包含socketcluster-client-java github项目时,我得到与上述完全相同的错误。

1 个答案:

答案 0 :(得分:0)

这些是我刚刚采取的步骤,一切正常:

  • cd /tmp
  • git clone https://github.com/MaxHoefl/SocketclusterclientExample.git
  • git clone git clone https://github.com/sacOO7/socketcluster-client-java.git
  • cd SocketclusterclientExample/Project
  • 使用settings.gradle
  • 修改project(':socketcluster-client-java').projectDir = new File('/Users/mh/workspaceJava/socketcluster-client-java')替换project(':socketcluster-client-java').projectDir = new File('/tmp/socketcluster-client-java')
  • gradle clean build - 建立成功。