Search code examples
javagradlebuild.gradlewar

Gradle WAR with compiled classes under WEB-INF/classes


I'm trying to port a legacy Java webapp project into gradle.

This is a snippet of my build.gradle

def customBuildPath = 'build/classes'

war {
    from(customBuildPath) {
        into 'WEB-INF/classes'
    }

    from('WebContent') {
        include 'Web/**/*'
        into ''
    }
}

dependencies {
  
    compile fileTree(dir: 'projectlibs/lib', include:'*.jar')
    compile fileTree(dir: 'build/classes', include:'**')
}

To maintain the custom structure I want to put all my *.class files under WEB-INF/classes and it works, but I find also the same *.class files under WEB-INF/lib.

My goal it to keep jars and classes in separated war folder.

Any thoughts?

Edit: Added dependencies{} to the build.gradle snippet.


Solution

  • Problem get solved with commenting out builded classes from the dependencies:

    def customBuildPath = 'build/classes'
    
    war {
        from(customBuildPath) {
            into 'WEB-INF/classes'
        }
    
        from('WebContent') {
            include 'Web/**/*'
            into ''
        }
    }
    
    dependencies {
      
        compile fileTree(dir: 'projectlibs/lib', include:'*.jar')
    //    compile fileTree(dir: 'build/classes', include:'**')
    }