2

I'm using gradle to build a groovy/java application. This worked fine until I added a dependency to google guice 3.0. Gradle does not add the guice jars to the compilation classpath, at least it seems so. I get errors like these:

C:\dev\workspaces\initial>gradle -q compileJava C:\dev\workspaces\initial\src\main\java\com\comp\test\solmon\di\GuiceDI.java:3: package com.google.inject does not exist import com.google.inject.Guice; ^ C:\dev\workspaces\initial\src\main\java\com\comp\test\solmon\di\GuiceDI.java:4: package com.google.inject does not exist import com.google.inject.Injector; 

In my build.gradle file I have the following dependencies:

dependencies{ runtime 'com.beust:jcommander:1.27' runtime "org.slf4j:slf4j-api:1.7.1" runtime "ch.qos.logback:logback-classic:1.0.7" runtime 'com.google.inject:guice:3.0' testRuntime 'junit:junit:4+' } 

I'm developing the application in Springsource Tool Suite 2.9.2 with its gradle plugin and it uses gradles dependency management to get all dependencies. Sts manages to compile the code just fine, it's only gradle that fails. I've tried to run the gradle compilation with the "--debug" parameter but I can not see which classpath gradle gives to the compiler.

Any ideas how to get gradle to compile my application?

1 Answer 1

3

You've added Guice to the runtime dependencies (i.e. the dependencies necessary to run the application, but not to compile it). Add it to the compile dependencies:

dependencies { ... compile 'com.google.inject:guice:3.0' } 

A compile dependency is also a runtime dependency, obviously.

Sign up to request clarification or add additional context in comments.

1 Comment

I changed dependency from runtime to compile and it finally worked. I obviously misinterpreted chapter 8.3 in the gradle doc. "runtime The dependencies required by the production classes at runtime. By default, also includes the compile time dependencies." . I thought that meant a runtime dependency is available at compile time.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.