Building a war containing jars


(Owen Cox) #1

Hi, I have an Dynamic Web Project in Eclipse that I really want to move to a Gradle build and additionally have the classes stored in a jar rather than separately.

i.e.

+docroot
–+ WEB-INF
----+ lib
------ mycompiledsrc.jar
------ mydependency1.jar
------ mydependency2.jar

– mywebresource1.jsp
– mywebresource2.jsp

But so far my attempts either give me compiled jar in the WEB-INF\lib but dependencies in the root directory, I’ve included my existing gradle.build below.

Any thoughts on this appreciated, I’m very new to Gradle from following tutorials so appreciate there may be some horrific problems with my approach where I’m unfamiliar with some concepts

description ="""

Project name: ${project.name}

Dynamic Web Project to build a war file containing built jars """

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

sourceCompatibility = 1.7
war.baseName = 'webtest'

// Set source directory
sourceSets {
    main {
        java {
            srcDir 'src'
        }
    }
}


repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
}

dependencies {
    providedCompile 'org.apache.tomcat:tomcat-catalina:7.0.47'
    compile group: 'commons-codec', name: 'commons-codec', version: '1.5'
    compile group: 'org.json', name: 'json', version: '20160810'
    compile group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.1'
    compile group: 'javax.mail', name: 'mail', version: '1.4.1'
    compile group: 'javax.websocket', name: 'javax.websocket-api', version: '1.1'
    
    compile fileTree(dir: "${webAppDirName}/WEB-INF/lib", include: '*.jar')
}

jar.enabled = true

jar {
    archiveName 'webtest.jar'
}

war {
    archiveName 'webapp.war'
    classpath = jar
    exclude('**/tomcat*.jar') 
    from(configurations.runtime)
    
}