Guice-3.0.jar wasn't included in the war file

It’s really strange that the guice-3.0.jar wasn’t included in the war file. I confirmed that I included this in build.gradle: compile ‘com.google.inject:guice:3.0’

Gradle looks good, but when using, a lot of problems. For example, doesn’t support GWT well, need to find my own solution. IDEA doesn’t support it well, especially for web applications. It seems that I have to give up gradle and go back to Maven which seems much maturer.

If Guice wasn’t included in the War, there is very likely a good reason for it. For example, maybe Guice was also a transitive ‘providedCompile’ dependency. In any case, we’d have to see a concrete example.

Regarding IntelliJ support, I recommend to check out IntelliJ 13 (EAP), which already has much better Gradle support than IntelliJ 12. I’m sure the folks at JetBrains would also be interested in getting feedback on what’s still missing.

Thanks for your quick reply.

As a new user from Maven, I spent a lot of time to investigate Gradle issues. I like the idea, but realised that may need to wait until it’s stronger in many detailed aspects.

Here is my gradle structure:

parent-project ├── build.gradle ├── settings.gradle ├── project-1-module │ ├── build.gradle ├── project-2-web │ ├── build.gradle

In the parent build.gradle, I have:

subprojects {

// DI

compile ‘com.google.inject:guice:3.0’ }

In the settings.gradle, I included both project-1-module and project-2-web.

I double confirmed that no providedCompile directly defined for guice-3.0 in any gradle build files, which was why I thought it’s really strange.

Thanks.

Another typical issue I’m encountering is that, gradle always conflicts with the existing local Maven repository. I have to delete each one from Maven repo manually, and then run the gradle command again. I could rm -rf ~/.m2, but it will take long time to download all dependencies again.

We’d need more information to investigate this. I’m not aware of any such issues with Gradle.

Gradle doesn’t use the local Maven repo, except when it’s explicitly told to do so. The only reason to do that is for exchanging artifacts with Maven builds (otherwise it’s better not to declare the local Maven repo). Recent Gradle versions have improved interoperability with the local Maven repo, and it should no longer be necessary to delete it.

I always included this:

repositories {

mavenLocal()

mavenCentral() }

Thanks for the info, I guess I don’t have to use mavenLocal() in gradle projects, only mavenCentral() is enough?

You shouldn’t use it, as it will lead to less reproducible builds (you might have something in your local Maven repo that someone else hasn’t).

Really appreciate it, I will remove that in my gradle build scripts.

I will check it later when I have more time available (maybe on weekend). Thanks anyway!

I arranged a sample project to reproduce this issue.

The project structure is:

gradle-sample-webapp jkwang$ tree
.
├── build.gradle
└── src
    ├── main
    │   ├── java
    │   ├── resources
    │   └── webapp
    │  
   ├── WEB-INF
    │  
   │   └── web.xml
    │  
   └── index.html
    └── test
        ├── java
        └── resources
  9 directories, 3 files

And the content of build.gradle is:

apply plugin: 'war'
apply plugin: 'jetty'
  archivesBaseName = 'gradle-sample-webapp'
  repositories {
    mavenCentral()
}
  jettyRun.contextPath = ''
  dependencies {
    // DI
    compile 'com.google.inject:guice:3.0'
    compile 'com.google.inject.extensions:guice-servlet:3.0'
    compile 'com.google.inject.extensions:guice-assistedinject:3.0'
    compile 'com.google.gwt.inject:gin:2.0.0'
      // GWT-Platform
    providedCompile 'com.gwtplatform:gwtp-mvp-client:1.0.3'
    providedCompile 'com.gwtplatform:gwtp-dispatch-client:1.0.3'
    compile 'com.gwtplatform:gwtp-dispatch-server-guice:1.0.3'
    compile 'com.gwtplatform:gwtp-dispatch-shared:1.0.3'
}

When I built war via: ‘gradle clean build’, I found guice-3.0.jar was not copied to war/WEB-INF/lib

Then I tried to replace two ‘providedCompile’ configurations to ‘compile’, and build again, the guice-3.0.jar was copied to war package successfully.

It seems ‘providedCompile’ override the previous defined ‘compile com.google.inject:guice:3.0’. Any ideas about this? Thanks a lot!

I arranged a sample project to reproduce this issue.

The project structure is:

gradle-sample-webapp jkwang$ tree
.
├── build.gradle
└── src
    ├── main
    │   ├── java
    │   ├── resources
    │   └── webapp
    │  
   ├── WEB-INF
    │  
   │   └── web.xml
    │  
   └── index.html
    └── test
        ├── java
        └── resources
  9 directories, 3 files

And the content of build.gradle is:

apply plugin: 'war'
apply plugin: 'jetty'
  archivesBaseName = 'gradle-sample-webapp'
  repositories {
    mavenCentral()
}
  jettyRun.contextPath = ''
  dependencies {
    // DI
    compile 'com.google.inject:guice:3.0'
    compile 'com.google.inject.extensions:guice-servlet:3.0'
    compile 'com.google.inject.extensions:guice-assistedinject:3.0'
    compile 'com.google.gwt.inject:gin:2.0.0'
      // GWT-Platform
    providedCompile 'com.gwtplatform:gwtp-mvp-client:1.0.3'
    providedCompile 'com.gwtplatform:gwtp-dispatch-client:1.0.3'
    compile 'com.gwtplatform:gwtp-dispatch-server-guice:1.0.3'
    compile 'com.gwtplatform:gwtp-dispatch-shared:1.0.3'
}

When I built war via: ‘gradle clean build’, I found guice-3.0.jar was not copied to war/WEB-INF/lib

Then I tried to replace two ‘providedCompile’ configurations to ‘compile’, and build again, the guice-3.0.jar was copied to war package successfully.

It seems ‘providedCompile’ override the previous defined ‘compile com.google.inject:guice:3.0’. Any ideas about this? Thanks a lot!

I think I found the answer here: http://www.gradle.org/docs/current/userguide/war_plugin.html

  The War plugin adds two dependency configurations: providedCompile and providedRuntime. Those configurations have the same scope as the respective compile and runtime configurations, except that they are not added to the WAR archive. It is important to note that those provided configurations work transitively. Let's say you add commons-httpclient:commons-httpclient:3.0 to any of the provided configurations. This dependency has a dependency on commons-codec. This means neither httpclient nor commons-codec is added to your WAR, even if commons-codec were an explicit dependency of your compile configuration. If you don't want this transitive behavior, simply declare your provided dependencies like commons-httpclient:commons-httpclient:3.0@jar.  

Sometimes this seems confusing as ‘commons-codec’ is an explicit dependency but still not added to WAR.