添加项目依赖项后出错

时间:2012-03-31 21:38:46

标签: gradle

我使用Gradle来构建如下所示的多个项目:

ares/build.gradle
ares/settings.gradle
ares/ares-gui/build.gradle
ares/ares-persistence/build.gradle
ares/ares-entities/build.gradle
ares/ares-persistence-config/build.gradle

所有项目都应用了java或scala gradle插件。

在项目ares-gui中,我添加了两个项目依赖项:

dependencies {
    ...
    myConfiguration project(':ares-entities')
    myConfiguration project(':ares-persistence')
    ...
}

当我运行gradle eclipse时,我收到此错误:

A problem occurred evaluating project ':ares-gui'.
> Could not resolve all dependencies for configuration ':ares-gui:runtime'.
   > Module version group:ares, module:ares-gui, version:1.0.0.SNAPSHOT, configuration:runtime declares a dependency on configuration 'default' which is not declared in the module descriptor for group:ares, module:ares-persistence, version:1.0.0.SNAPSHOT

有趣的是,当我只留下一个依赖(ares-entities)时,一切都很好。

知道为什么会这样吗?

编辑:这实际上非常有趣:当我将ares-persistence的名称更改为ares-bpersistence(在ares-gui之前按字典顺序排列)时,问题就消失了!一个错误?

EDIT2:以下是有关此问题的更多信息:

Gradle版本:

------------------------------------------------------------
Gradle 1.0-milestone-9
------------------------------------------------------------

Gradle build time: wtorek, 13 marzec 2012 16:10:09 UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Ivy: 2.2.0
JVM: 1.6.0_26 (Sun Microsystems Inc. 20.1-b02)
OS: Linux 2.6.38-13-generic amd64

堆栈跟踪:

org.gradle.api.GradleScriptException: A problem occurred evaluating project ':ares-gui'.
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:127)
    at org.gradle.configuration.BuildScriptProcessor.evaluate(BuildScriptProcessor.java:38)
    at org.gradle.configuration.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:43)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:462)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:74)
    at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:23)
    at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:21)
    at org.gradle.configuration.DefaultBuildConfigurer$1.execute(DefaultBuildConfigurer.java:38)
    at org.gradle.configuration.DefaultBuildConfigurer$1.execute(DefaultBuildConfigurer.java:35)
    at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:438)
    at org.gradle.api.internal.project.AbstractProject.allprojects(AbstractProject.java:433)
    at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:139)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:110)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:78)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:45)
    at org.gradle.launcher.daemon.protocol.Build.run(Build.java:67)
    at org.gradle.launcher.daemon.protocol.Build.run(Build.java:63)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:45)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:45)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.ReturnResult.execute(ReturnResult.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$4.call(ForwardClientInput.java:116)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$4.call(ForwardClientInput.java:114)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:114)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:61)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy.doBuild(StartBuildOrRespondWithBusy.java:49)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.HandleStop.execute(HandleStop.java:36)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.CatchAndForwardDaemonFailure.execute(CatchAndForwardDaemonFailure.java:32)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.HandleClientDisconnectBeforeSendingCommand.execute(HandleClientDisconnectBeforeSendingCommand.java:21)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.StopConnectionAfterExecution.execute(StopConnectionAfterExecution.java:27)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
    at org.gradle.launcher.daemon.server.exec.DefaultDaemonCommandExecuter.executeCommand(DefaultDaemonCommandExecuter.java:55)
    at org.gradle.launcher.daemon.server.Daemon$1$1.run(Daemon.java:123)
    at org.gradle.messaging.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
Caused by: org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':ares-gui:runtime'.
    at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver.wrapException(ErrorHandlingArtifactDependencyResolver.java:47)
    at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver.access$000(ErrorHandlingArtifactDependencyResolver.java:26)
    at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver$BrokenResolvedConfiguration.rethrowFailure(ErrorHandlingArtifactDependencyResolver.java:127)
    at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationFileCollection.getFiles(DefaultConfiguration.java:458)
    at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.getFiles(DefaultConfiguration.java:203)
    at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration_Decorated.getFiles(Unknown Source)
    at org.gradle.api.internal.file.AbstractFileCollection$1.getFiles(AbstractFileCollection.java:88)
    at build_12d77nfltt9q8t8qb7c0m6lmai$_run_closure4_closure7.doCall(/home/ghik/iosr/ares/ares-gui/build.gradle:45)
    at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:141)
    at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:90)
    at org.gradle.api.plugins.osgi.OsgiPluginConvention.osgiManifest(OsgiPluginConvention.java:65)
    at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:196)
    at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:102)
    at org.gradle.api.internal.plugins.DefaultConvention$ExtensionsDynamicObject.invokeMethod(DefaultConvention.java:212)
    at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:99)
    at org.gradle.api.internal.project.DefaultProject_Decorated.invokeMethod(Unknown Source)
    at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.groovy:73)
    at build_12d77nfltt9q8t8qb7c0m6lmai$_run_closure4.doCall(/home/ghik/iosr/ares/ares-gui/build.gradle:39)
    at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:141)
    at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:109)
    at org.gradle.api.internal.AbstractTask.configure(AbstractTask.java:392)
    at org.gradle.api.internal.AbstractTask.configure(AbstractTask.java:57)
    at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:133)
    at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:90)
    at org.gradle.api.internal.DefaultNamedDomainObjectCollection$ContainerElementsDynamicObject.invokeMethod(DefaultNamedDomainObjectCollection.java:315)
    at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:99)
    at org.gradle.api.internal.project.DefaultProject_Decorated.invokeMethod(Unknown Source)
    at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.groovy:73)
    at build_12d77nfltt9q8t8qb7c0m6lmai.run(/home/ghik/iosr/ares/ares-gui/build.gradle:38)
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
    ... 52 more
Caused by: java.lang.RuntimeException: Module version group:ares, module:ares-gui, version:1.0.0.SNAPSHOT, configuration:runtime declares a dependency on configuration 'default' which is not declared in the module descriptor for group:ares, module:ares-persistence-config, version:1.0.0.SNAPSHOT
    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$DependencyEdge.calculateTargetConfigurations(DependencyGraphBuilder.java:322)
    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder$DependencyEdge.attachToTargetConfigurations(DependencyGraphBuilder.java:283)
    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder.traverseGraph(DependencyGraphBuilder.java:117)
    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DependencyGraphBuilder.resolve(DependencyGraphBuilder.java:53)
    at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver.resolve(DefaultDependencyResolver.java:67)
    at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver$1.create(CacheLockingArtifactDependencyResolver.java:36)
    at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver$1.create(CacheLockingArtifactDependencyResolver.java:34)
    at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:126)
    at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:99)
    at org.gradle.api.internal.artifacts.ivyservice.DefaultCacheLockingManager.useCache(DefaultCacheLockingManager.java:49)
    at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver.resolve(CacheLockingArtifactDependencyResolver.java:34)
    at org.gradle.api.internal.artifacts.ivyservice.SelfResolvingDependencyResolver.resolve(SelfResolvingDependencyResolver.java:42)
    at org.gradle.api.internal.artifacts.ivyservice.ShortcircuitEmptyConfigsArtifactDependencyResolver.resolve(ShortcircuitEmptyConfigsArtifactDependencyResolver.java:78)
    at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver.resolve(ErrorHandlingArtifactDependencyResolver.java:36)
    at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.getResolvedConfiguration(DefaultConfiguration.java:236)
    at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration_Decorated.getResolvedConfiguration(Unknown Source)
    at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationFileCollection.getFiles(DefaultConfiguration.java:456)
    ... 78 more

当我从构建脚本中删除一行时,问题也会消失:

war {
    manifest = osgiManifest {
        ...
        // this line is causing problems
        def someLibs = classpath.files.collect{ 'WEB-INF/lib/'+it.name }
        ...
    }
}

1 个答案:

答案 0 :(得分:4)

上面代码中的

classpath.files在构建配置时解析文件集合。应尽可能避免这种情况。首先,这意味着无论在哪个项目执行哪个任务,都会为每个构建(可能涉及下载)解析文件集合。在这种特殊情况下,它还会导致对:ares-persistence的项目依赖性得到解决,但由于该项目的构建脚本尚未进行评估,因此失败了。

解决方案是确保只在执行时解析文件集合。如何做到这一点取决于你想要达到的具体情况。常见的解决方案是使用惰性Gradle API,在使用Gradle提供的众多钩子之一注册的回调中进行工作,或者在doFirst {}块中进行工作。