Skip to content

signal7/gradle-web-multiproject-sample

Repository files navigation

gradle-web-multiproject-sample

This Gradle Project Constists of two projects.

  • webapp produces a war
  • common produces a jar and is required by webapp

The Problem:

webapp requires common-math 2.2 and common has an older version of that: common-math 2.1

Gradle itself knows that common-math 2.2 overwrites 2.1

compile - Compile classpath for source set 'main'.
+--- org.apache.commons:commons-math:2.2
+--- master:common:unspecified
|    \--- org.apache.commons:commons-math:2.1 -> 2.2
\--- javax.servlet:servlet-api:2.5

default - Configuration for default artifacts.
+--- org.apache.commons:commons-math:2.2
+--- master:common:unspecified
|    \--- org.apache.commons:commons-math:2.1 -> 2.2
\--- javax.servlet:servlet-api:2.5

providedCompile - Additional compile classpath for libraries that should not be part of the WAR archive.
\--- javax.servlet:servlet-api:2.5

providedRuntime - Additional runtime classpath for libraries that should not be part of the WAR archive.
\--- javax.servlet:servlet-api:2.5

runtime - Runtime classpath for source set 'main'.
+--- org.apache.commons:commons-math:2.2
+--- master:common:unspecified
|    \--- org.apache.commons:commons-math:2.1 -> 2.2
\--- javax.servlet:servlet-api:2.5

But when gradle generates the eclipse files and you deploy the webapp to a tomcat in eclipse, the deployment folder looks like that:

Tomcat Deployment Folder

The following eclipse files are being generated by gradle

common/.classpath

the common-math 2.1 dependency is contained, which is correct for the common project in isolation

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="output" path="bin"/>
	<classpathentry kind="src" path="src/main/java"/>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true"/>
	<classpathentry sourcepath=".../commons-math-2.1-sources.jar" kind="lib" path=".../commons-math-2.1.jar" exported="true">
		<attributes>
			<attribute name="org.eclipse.jst.component.dependency" value="../"/>
		</attributes>
   </classpathentry>
</classpath>

common/.settings/org.eclipse.wst.common.component

<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="2.0">
	<wb-module deploy-name="common">
		<wb-resource deploy-path="/" source-path="src/main/java"/>
	</wb-module>
</project-modules>

webapp/.classpath

the common project dependency is contained

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
	<classpathentry kind="output" path="bin"/>
	<classpathentry kind="src" path="src/main/java"/>
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true"/>
	<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container" exported="true"/>
	<classpathentry kind="src" path="/common" exported="true"/>
	<classpathentry sourcepath=".../commons-math-2.2-sources.jar" kind="lib" path=".../commons-math-2.2.jar" exported="true">
		<attributes>
			<attribute name="org.eclipse.jst.component.nondependency" value=""/>
		</attributes>
	</classpathentry>
	<classpathentry sourcepath=".../servlet-api-2.5-sources.jar" kind="lib" path=".../servlet-api-2.5.jar" exported="true">
		<attributes>
			<attribute name="org.eclipse.jst.component.nondependency" value=""/>
		</attributes>
	</classpathentry>
</classpath>

webapp/.settings/org.eclipse.wst.common.component

the common project dependency is part of the component descriptor and therefor part of the deployment. the problem is here, that all transitive dependencies are part of the deployment as well. and so is commons-math-2.1.jar

<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="2.0">
	<wb-module deploy-name="webapp">
		<property name="context-root" value="webapp"/>
		<wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/>
		<wb-resource deploy-path="/" source-path="src/main/webapp"/>
		<dependent-module deploy-path="/WEB-INF/lib" handle="module:/resource/common/common">
			<dependency-type>uses</dependency-type>
		</dependent-module>
		<dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/lib/.../commons-math-2.2.jar">
			<dependency-type>uses</dependency-type>
		</dependent-module>
	</wb-module>
</project-modules>

Conclusion

The generated files for the common project seems right, because the depending project needs to determine if some transitive dependencies should be excluded or not. For this case it seems, that the webapp/.settings/org.eclipse.wst.common.component file needs to exclude commons-math-2.2 from the dependent module:

<dependent-module deploy-path="/WEB-INF/lib" handle="module:/resource/common/common">
	<dependency-type>uses</dependency-type>
</dependent-module>

We are not sure, if there is a way to accomplish this.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published