springtomcatintellij-ideagradlespring-loaded

Intellij + Gradle + SpringLoaded + Tomcat


I'm developing Spring rest service using Gradle, Intellij, and Tomcat. I want to reload my changes without redeploying, so I use SpringLoaded. But it doesn't reload my project. Even hot swap doesn't work. Here is my build.gradle:

def group = 'com.expecker'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'maven'
sourceCompatibility = 1.8
targetCompatibility = 1.8
def springVersion = '4.0.0.RELEASE'
def hibernateVersion = '5.0.7.Final'
def junitVersion = '4.11'
repositories {
    mavenCentral()
}
dependencies {
    testCompile group: 'junit', name: 'junit', version: junitVersion
    compile "org.springframework:spring-core:$springVersion"
    compile "org.springframework:spring-web:$springVersion"
    compile "org.springframework:spring-webmvc:$springVersion"
    compile "org.springframework:spring-orm:$springVersion"
    compile "org.springframework:spring-jdbc:$springVersion"
    compile "org.springframework:spring-tx:$springVersion"
    compile "org.springframework:spring-orm:$springVersion"
    compile "org.springframework:spring-context:$springVersion"
    compile 'javax.servlet:javax.servlet-api:3.1.0'
    compile 'jstl:jstl:1.2'
    compile 'javax.servlet.jsp:jsp-api:2.2'
//  compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13' it seems like this library isn't compatible with spring 4.1.x
    compile 'com.fasterxml.jackson.core:jackson-databind:2.6.4'
    compile "org.hibernate:hibernate-core:$hibernateVersion"
    compile "org.hibernate:hibernate-entitymanager:$hibernateVersion"
    compile 'commons-dbcp:commons-dbcp:1.4'
    //compile('org.springframework:springloaded:1.2.5.RELEASE')
}
buildscript {
    repositories { jcenter() }
    dependencies {
        classpath 'org.springframework:springloaded:1.2.5.RELEASE'
    }
}
apply plugin: 'idea'
idea {
    module {
        inheritOutputDirs = false
        outputDir = file("$buildDir/classes/main/")
    }
}
/*
When built in OpenShift the 'openshift' profile will be used when
invoking mvn.
Use this profile for any OpenShift specific customization your app
will need.
By default that is to put the resulting archive into the 'webapps'
folder.
http://maven.apache.org/guides/mini/guide-building-for-different-environments.html
*/
gradle.buildFinished { buildResult ->
    println 'Building pom.xml...'
    pom {
        project {
            groupId "${group}"
            artifactId 'app'
            version "${version}"
            packaging 'war'
        }.withXml {
            asNode().appendNode('profiles').
                    appendNode('profile').with {
                appendNode('id', 'openshift')
                appendNode('build').with {
                    appendNode('finalName', 'expecker')
                    appendNode('plugins').appendNode('plugin').with {
                        appendNode('artifactId', 'maven-war-plugin')
                        appendNode('version', '2.1.1')
                        appendNode('configuration').with {
                            appendNode('outputDirectory', 'deployments')
                            appendNode('warName', 'expecker')
                        }
                    }
                }
            }
        }
    }.writeTo("pom.xml")}

in my Tomcat configuration I have vm option -javaagent:|here is my path to springloaded.jar| -noverify. I chose exploded artifact on deployment tab.

As you can see, I tried to include my springloaded jar to classpath (I don't know why it's needed, I saw it in some articles). I tried to add this jar as a compile dependency, but then I can't build the project. Also I tried to not include it, only set in vm options. Here are some my observations:


Could anyone help me?


Solution

  • My fault, spring loaded doesn't support adding of new classes. So, actually, everything works as expected.