Multiproject testCompile dependencies not seen by dependant project


(Mark Fisher) #1

This question has grown out of a setup I posted at http://forums.gradle.org/gradle/topics/project_dependencies_getting_wrong_paths.

I’m trying to find out how to use the testCompile jars between projects.

My setup is like this:

(ProjectA/Base/build.gradle)

dependencies {
    ...
    compile files("lib/gson-2.2.1.jar")
    testCompile files("lib/mockito-all-1.8.5.jar")
    ... other test jars
}

(ProjectB/Base/build.gradle)

dependencies {
    compile project(':ProjectA.Base')
    testCompile project(':ProjectA.Base')
}

When I try to build ProjectB/Base, the compileTestJava task fails unable to find any of the mockito classes. If I change from “testCompile” to “compile” in ProjectA’s build script, projectB compiles and the tests run fine.

Is there something else I need to do to allow project B to pick up Project A’s testCompile jars?

Thanks in advance.


(Peter Niederwieser) #2

Stack Overflow has a couple of answers:

http://stackoverflow.com/questions/5644011/multi-project-test-dependencies-with-gradle http://stackoverflow.com/questions/5144325/gradle-test-dependency

Searching this forum should bring up further answers.


(Mark Fisher) #3

Hi Peter,

Thanks for the reply, I did find these answers on SO already, but from what I can tell (probably my lack of understanding of gradle), they are exposing the generated classes from one project to another. I just want the mockito jar file that’s in projectA to be available to projectB without having to copy it into the lib dir of projectB.

My search on the forum (“testcompile multiproject”) resulted in 3 hits, 1 was my own question, 2 of which were again related (in so far as I read them) to giving projectB access to the test classes in projectA, not the libraries used to compile them.

I’m just reading your reply http://stackoverflow.com/a/10633623/690139 about configuration injection to see if that will solve my library issue, i.e. “Depending on a project doesn’t pull in its testCompile/testRuntime dependencies. It’s expected that you have to declare JUnit for each project that needs it. To avoid repetition, you can use configuration injection to declare the commonalities between your projects”

If I read your comment correctly, i’ll never be able to declare a jar like mockito or junit in one project and get it on the classpath of a project that includes it and depends on it. Is this a correct reading of it?


(Peter Niederwieser) #4

In short, a project dependency will give you its default artifacts, compile and runtime dependencies, but not its testCompile/testRuntime dependencies. See the Gradle user guide for more on this topic (e.g. project configuration dependencies).

Anyway, if a project (directly) uses a dependency, it should say so. If B uses Mockito for its tests, then it should put it on its ‘testCompile’ configuration. Relying on Mockito being pulled in transitively is the wrong approach here.


(Mark Fisher) #5

Ok, thanks for this.

I’m essentially gradle-ising an existing setup that’s based on eclipse projects and some very tired shell scripts for building.

In my case, both ProjectA and ProjectB are eclipse projects, we put the libraries for testing in projectA which exports them and ProjectB picks them up from having the eclipse project to project link, so no need to duplicate test jars to every project, and i was trying to emulate that library exporting behaviour in gradle.


(Jon Austen) #6

Question for you guys. I am trying to do a multi-project build, but the code suggested in the documentation doesn’t compile. I think it has something to do with the new property format (i.e. “project.ext.blah”) . I have a build.gradle in my root project and I am trying to control the sub-projects from the main build file. Here is my code:

project(':google').identify << {
    project.ext.projVersion = '0.99.2'
    project.ext.projTitle = 'WebDriver For Google'
}
  project(':bing').identify << {
    project.ext.projVersion = '0.99.2'
    project.ext.projTitle = 'WebDriver For Bing'
}

And the exception I get is:

* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'WebDriverTestingTemplate'.
 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:463)
 at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:75)
 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:439)
 at org.gradle.api.internal.project.AbstractProject.allprojects(AbstractProject.java:434)
 at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
 at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:142)
 at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
 at org.gradle.initialization.DefaultGradleLauncher.getBuildAnalysis(DefaultGradleLauncher.java:92)
 at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.java:70)
 at org.gradle.tooling.internal.provider.DelegatingBuildModelAction.run(DelegatingBuildModelAction.java:44)
 at org.gradle.tooling.internal.provider.ConfiguringBuildAction.run(ConfiguringBuildAction.java:95)
 at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:39)
 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:126)
 at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:42)
 at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:126)
 at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
 at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:126)
 at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33)
 at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:126)
 at org.gradle.launcher.daemon.server.exec.ReturnResult.execute(ReturnResult.java:34)
 at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:126)
 at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:70)
 at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:68)
 at org.gradle.util.Swapper.swap(Swapper.java:38)
 at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:68)
 at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:126)
 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:126)
 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:126)
 at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:45)
 at org.gradle.launcher.daemon.server.DaemonStateCoordinator.runCommand(DaemonStateCoordinator.java:185)
 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:126)
 at org.gradle.launcher.daemon.server.exec.HandleStop.execute(HandleStop.java:36)
 at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:126)
 at org.gradle.launcher.daemon.server.exec.CatchAndForwardDaemonFailure.execute(CatchAndForwardDaemonFailure.java:32)
 at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:126)
 at org.gradle.launcher.daemon.server.exec.DefaultDaemonCommandExecuter.executeCommand(DefaultDaemonCommandExecuter.java:52)
 at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.handleCommand(DefaultIncomingConnectionHandler.java:142)
 at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.run(DefaultIncomingConnectionHandler.java:116)
 at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
Caused by: org.gradle.api.UnknownProjectException: Project with path ':google' could not be found in root project 'WebDriverTestingTemplate'.
 at org.gradle.api.internal.project.AbstractProject.project(AbstractProject.java:409)
 at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:216)
 at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:122)
 at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147)
 at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.java:83)
 at build_6qd9vhpmvap6jo0r4hpquaskj7.run(C:\Eclipse32\workspace\WebDriverTestingTemplate\build.gradle:78)
 at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
 ... 54 more

(Peter Niederwieser) #7

This question is unrelated to the main topic, so I created a new topic. Please reference the new topic here: Cannot find project in multi-project build