Gradle multiproject: How refer correctly any content from WEB-INF for testing

(Manuel Jordan) #1

Hello Gradle developers

  • I am working with a Spring/Gradle multi module project.
  • For some modules, I am able to test them in isolation. I mean, test just a specific module. And them pass
  • I am able to create a .war file and work in peace in Apache Tomcat

The problem is about testing and is for the module working in a web environment. I have the following:

project(':web-27-controller') {
	description 'Web - Controller & Rest'
	dependencies {
	   compile project(':web-27-service-api')
	   compile project(':web-27-support')
 	   testCompile project(':web-27-config')
 	   testRuntime project(':web-27-config').sourceSets.test.output
 	   testRuntime project(':web-27-repository-jdbc')
 	   testRuntime project(':web-27-service-impl')
 	   testCompile project(':web-27-web')
 	   testRuntime project(':web-27-web').sourceSets.main.output


When I execute that test for that specific module, I get:

Caused by: ServletContext resource [/WEB-INF/tiles/definition/tiles-definitions.xml] cannot be resolved to URL because it does not exist

Well I can see in the other module web-27-web the /WEB-INF/tiles/definition/tiles-definitions.xml file. It of course within the webapp directory and remember, when I create the .war file, it works fine in Apache Tomcat

I know that Gradle respects or uses:

  • src/main/java
  • src/main/resources
  • src/test/java
  • src/test/resources

But seems that is not referring to the WEB-INF location

I have the following about web-27-web (consider it unstable because I have trying to get this working)

project(':web-27-web') {
	description 'Web (JSP, JS, CSS)'
	apply plugin: 'war'
	project.webAppDirName = 'WebContent'
	dependencies {
		compile fileTree(dir: "WebContent/WEB-INF/tiles/definition", include: '*.xml')
		testCompile fileTree(dir: "WebContent/WEB-INF/tiles/definition", include: '*.xml')
		testRuntime fileTree(dir: "WebContent/WEB-INF/tiles/definition", include: '*.xml')
				compile project("$it")
		//Apache Tiles
	 	].each {
	 		runtime "org.apache.tiles:$it:$tilesVersion"
	 		testCompile "org.apache.tiles:$it:$tilesVersion" 
	 		testRuntime "org.apache.tiles:$it:$tilesVersion"	 		
		compile "javax.servlet:jstl:$jstlVersion"
		testRuntime "javax.servlet:jstl:$jstlVersion"
		//Servlet API
		providedCompile "javax.servlet:javax.servlet-api:$javaxServletApiVersion"
		testRuntime "javax.servlet:javax.servlet-api:$javaxServletApiVersion"
	war {
		baseName = warBaseName


What is missing or wrong?.

Thanks in advanced.