WEB-INF/classes empty upon Gradle Build

Here is the build.gradle file

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'ear'

def binDir = file("bin")
def libDir = "WebContent/WEB-INF/lib"
def testReportDir = file('testReport')
def outputDir = file("output")
def envParam = "local"

sourceSets {
    project.webAppDirName = 'WebContent'
    main {
        java { srcDirs = ['src/main/java'] }
        resources { srcDirs = ['src/main/resources'] }
         output.classesDir = binDir
    }

    test {
        java { srcDirs = ['src/test/java', 'src/main/java'] }
        resources { srcDirs = ['src/test/resources'] }
        output.classesDir = binDir
        compileClasspath = sourceSets.main.compileClasspath
        runtimeClasspath = output + compileClasspath
    }
}

dependencies {
    compile fileTree(dir: libDir, include: ['*.jar'])
    testCompile 'junit:junit:4.12'
}

task cleanDirs(type: Delete) {
    //clean tasks
}


war {
    dependsOn cleanDirs
    destinationDir(binDir)

}



ear {
    dependsOn war
    appDirName '../XYZApplicationEAR/META-INF'
    destinationDir(outputDir)   

    deploymentDescriptor {
        displayName = "XYZApplicationEAR"  
        webModule("XYZApplication.war", "xyzapp")  
    }

}

Everything is fine but the issue is, inside the generated war file… under WEB-INF/classes, the compiled classes are missing. The only present items are the properties files from the resources(src/main/resources) package.

Anyone can help us on this? thanks

Project Format below

XYZApplication
>>src
>>WebContent
>>>>META-INF
>>>>WEB-INF

gradle.build  (placed under XYZApplication)
gradle.properties (placed under XYZApplication)

XYZApplicationEAR
(the parent ear project that contains web nodule XYZApplication)

XYZApplication is the web module. XYZApplication is the ear module

This is version Gradle 3.1

You don’t need to configure the sourceSets manually. They are already set up for you out-of-the-box by the java plugin. It looks like you are going with the default Gradle conventions anyway so no need to reconfigure the,. Maybe you accidentally introduced an issue there. I’d suggest you remove that code and see if you still run into the issue.

remove the whole sourceSets block?

Correct. BTW: project.webAppDirName = 'WebContent' goes to the top level of the build script and doesn’t require the use of the project variable. It’s used implicitly.

Did what you suggested. Still the same result.

WEB-INF/classes folder is empty. Same thing in the generated war file.

I finally got it to work. I added the ff:

  1. created a copy task that copies contents of bin to WEB-INF/classes
  2. Added the ff. lines

copyTask.mustRunAfter compileJava
compileJava.mustRunAfter cleanDirs

But there’s a new problem. The generated war file is not being included in the ear file

You shouldn’t have to create a copy task to make it work for your project. Here’s what I suggest. How about you put a sample project on GitHub and I’ll send you a pull request?