Using Spring Tool Suite 3.5 with gradle plugin, gradle 1.11
I want to achieve this: extract the content of project dependend library into WAR file both when running gradle build
from command line and when deploying from Eclipse into Tomcat.
I have my build.gradle project like this:
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
webAppDirName = 'WebContent'
configurations{
common
}
eclipse{
wtp {
facet{
facet name: 'jst.web', version: '3.0'
facet name: 'java', version: '1.7'
}
}
}
war{
from ({zipTree(configurations.common.singleFile)}){
into('common')
}
}
dependencies {
common "group:artifact:version:common@jar"
}
Eclipse doesn't extract the configurations.common
as prescribed in the war{}
section, so
I had to change the script slightly:
eclipse{
wtp{
facet{
...
}
component{
resource sourcePath: "build/common", deployPath: "/common"
}
}
}
task extractCommon(type:Copy){
from {
configurations.common.collect{ zipTree(it) }
}
exclude 'META-INF/**'
into "$buildDir/common"
}
eclipseClasspath.dependsOn(extractCommon)
This way the dependend JAR gets extracted before re-creating the eclipse project files and settings, but unfortunately the webAppDirName
disappears from the Deployment Assembly settings in eclipse project.
So another workaround:
eclipse{
wtp{
facet{
...
}
component{
resource sourcePath: "build/common", deployPath: "/common"
resource sourcePath: "$webAppDirName", deployPath: "/"
}
}
}
This way the eclipse behaves as intended, but it looks cumbersome and I feel that I am missing something and that eclipse-wtp plugin should be doing this automatically somehow.
Is there easier way to achieve:
- Eclipse to follow the prescribed behavior defined in
war{}
block when deploying from Eclipse (extracting some JARs before creating the web app). - Define
resources
in an incremental way without purging thewebAppDirName
folder from the deployment
EDIT: Let me rephrase the problem:
If I have a war project with typical directory structure
src
main
java
webapp
generated_source
And build.gradle like this:
apply plugin:'java'
apply plugin:'war'
apply plugin:'eclipse-wtp'
eclipse.wtp.component.resource(sourcePath:'generated_source', deployPath:'/WEB-INF')
Then after running gradle cleanEclipse eclipseWtpComponent
the resulting file - .settings/org.eclipse.wst.common.component
Should look like this:
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="2.0">
<wb-module deploy-name="gradleissue">
<property name="context-root" value="gradleissue"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/>
<wb-resource deploy-path="/" source-path="src/main/webapp"/>
<wb-resource deploy-path="/WEB-INF/" source-path="generated_source"/>
</wb-module>
</project-modules>
But it looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="2.0">
<wb-module deploy-name="gradleissue">
<property name="context-root" value="gradleissue"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/>
<wb-resource deploy-path="/WEB-INF/" source-path="generated_source"/>
</wb-module>
</project-modules>
The /src/main/webapp
folder disappeared from the deployment assembly. I have a bad feeling, that this is not what it's supposed to do.
I also checked the tests in https://github.com/gradle/gradle/blob/master/subprojects/ide/src/test/groovy/org/gradle/plugins/ide/eclipse/EclipseWtpPluginTest.groovy and it looks like this case is missing (I am not a groovy guy).