Create a JAR containing classes and resources from webapp using Gradle

I would like to create a jar from the contents of a WAR using gradle. The result I want is quite like what the archiveClasses = true setting of maven-war-plugin does.

I understand that the gradle war plugin doesn't seem to do this (as per this stackoverflow question).

Is there a way to do this manually? Say by manipulating the gradle jar task to collect the required parts from the WEB-INF folder?

When I just use the default jar task it doesn't get the resources from the WEB-INF directory.

The reason I want to do this is because I have modularised a WAR and the modules depend on common resources in the WAR (FreeMarker files in my case). I want to be able to test each module by depending on JAR created from the WAR.

I understand I could also create a "common" jar that held all the resources and have both the WAR and the module depend on this, but it would be more convenient to create a JAR form the WAR as per the maven-war-plugin.


您可以添加它以在创建的jar文件的根目录中同时包含src / main / resources和scr / main / webapp:

sourceSets {
    main {
        resources {
            srcDirs "src/main/resources", "src/main/webapp"
        }
    }
}

So here is how I solved it (not sure if this is the best way):

jar {
    from ("${projectDir}/src/main/webapp/WEB-INF") {
        include('freemarker/**')
    }
}

I also found this alternative in the Gradle forums but I couldn't get the line resources.srcDir("src/main/webapp").exclude('images/') to compile, but I really like the idea of somehow just adding to the jar task's default resources directories. Edit : I think my first example above is as good as it gets.

链接地址: http://www.djcxy.com/p/76948.html

上一篇: SBT能否刷新git uri的依赖(总是或按需)?

下一篇: 使用Gradle从webapp创建一个包含类和资源的JAR