1

Update Originally there was a Tomcat exception upon initialization of my gradle build's war file. After some help from the author, it is now deploying and running albiet partially. This may be due to a bug in Gradle. Editing with the updated build.gradle and SpringData Rest output at root of service below.

I have been attempting to compile and run a Spring Data Rest project originally written in Maven.. for Gradle instead.

Tutorial location : http://www.javacodegeeks.com/2013/08/spring-data-rest-in-action.html

My project builds fine, into a war via the following

*build.gradle *

buildscript {
    repositories {
        maven { url "http://repo.spring.io/libs-milestone" }
        mavenLocal()
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'war'

war {
    baseName = 'whichdegree-service'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
    maven { url "http://repo.spring.io/libs-milestone" }
    maven { url "https://repository.jboss.org/nexus/content/repositories/releases" }
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:0.5.0.M5")
    compile("org.springframework:spring-orm:4.0.0.M3")
    compile("org.springframework.data:spring-data-jpa:1.3.2.RELEASE")
    compile("org.springframework.data:spring-data-commons-core:1.3.2.RELEASE")
    compile("org.hibernate:hibernate-entitymanager:4.2.1.Final")
    //Added by author of tutorial
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+'
    compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'

    //Spring-Data-REST, upgraded to 2.0.0 and Tomcat served war properly
    compile("org.springframework.data:spring-data-rest-webmvc:2.0.0.M1")

    //HSQL DB
    compile("org.hsqldb:hsqldb:1.8.0.10")

    testCompile("junit:junit:4.11")
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.8'
}

task copyDependencies(type: Copy) {
    description = 'Copy dependencies to libs. Useful for Eclipse'
    libDir = new File(project.projectDir, '/libs')
    println libDir
    println 'Adding dependencies from compile configuration'
    for(file in configurations.compile) {
        println 'Added ' + file
        copy 
        {
            from file
            into libDir
        }
    }
}

Switching to 2.0 version of Spring Data REST fixed deployment, however the service doesn't seem to be active or working:

Expected Result of GET at service_root/

{
  "links" : [ {
    "rel" : "books",
    "href" : "http://localhost:8080/books"
  }, {
    "rel" : "authors",
    "href" : "http://localhost:8080/authors"
  } ],
  "content" : [ ]
}

Actual Result of GET at my service

{
  "links" : [ ],
  "content" : [ ]
}

Wondering if this is perhaps a bug in Gradle itself, not wiring Spring-Data-Rest properly..?

Erik
  • 2,782
  • 3
  • 34
  • 64
  • What version of Spring ar you using? I think you need at least 3.1 for the missing stuff it's complaining about. http://docs.spring.io/spring/docs/3.1.x/javadoc-api/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.html#getReturnValueHandlers() – Jason C Nov 22 '13 at 18:53
  • where do I check that, other than the gradle.build file? the POM.xml ? – Erik Nov 22 '13 at 21:02
  • 1
    okay after checking with others, I am going to revert from 4.0 Spring ORM down to org.springframework:spring-orm:3.2.2.RELEASE – Erik Nov 22 '13 at 22:53
  • 1
    My dependencies seemed mixed with 3.2.2.RELEASE and 4.0.0 based stuff like WebMVC even though I don't reference 4.0 .. I guess I need to lookup a tutorial on Gradle + Spring and how to control it better – Erik Nov 22 '13 at 23:19
  • Let us know when you find a solution. I wish I could be of more help, but I have a personal preference of avoiding build systems that automatically download dependencies. – Jason C Nov 23 '13 at 00:38
  • I found a partial solution, thanks to the author of the original project.. will update the question. – Erik Nov 23 '13 at 01:31
  • I briefly read your comments in the tutorial. JDBC driver classes must go in Tomcat's 'lib' directory (see http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html#DriverManager,_the_service_provider_mechanism_and_memory_leaks and http://stackoverflow.com/questions/6981564/why-jdbc-driver-must-been-put-in-tomcat-home-lib-folder for an explanation of why) to be automatically registered. They can't just be packaged in your WAR unless you explicitly register them. Perhaps that is related to your new issue. – Jason C Nov 23 '13 at 01:42
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/41742/discussion-between-erik-and-jason-c) – Erik Nov 23 '13 at 01:44
  • Re: Your updated question: I think you are overstating Gradle's role here. Gradle is just a build system. It grabs JARs, compiles your code with `javac`, and sticks everything in a WAR. It has nothing to do with the functionality of your application outside of possibly grabbing an unexpected version of some third-party library. If your application isn't functioning as expected, debug it. Check tomcat logs, add error handling. You may want to consider just compiling this code manually or using Eclipse or something. You are trying to learn Spring but getting sidetracked by your build system. – Jason C Nov 23 '13 at 02:51
  • In other words, Gradle isn't "wiring" anything together. It's just blindly putting third-party JARs in your classpath, the same way you'd do it manually -- there isn't anything more to it. Your application isn't "written in Maven" or "written in Gradle". It's written in Java. And Maven/Gradle/Ant/Make/batch files and shell scripts are one of many tools that are nothing more than automating the process of you downloading JAR files and typing `javac` on the command line. – Jason C Nov 23 '13 at 02:53
  • This project is working as a Maven build.. the code should function if built properly in Gradle. Sorry if I'm not clearly stating that, I understand it's all Java in the end. – Erik Nov 23 '13 at 03:04

0 Answers0