3

I have customModule which is dependant on user-portal app. user-portal is dependent on util module

Here are the relevant POM's

customModule POM

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
        <artifactId>parent-build</artifactId>
        <groupId>com.myComp.user</groupId>
        <version>1</version>
        <relativePath>../../pom.xml</relativePath>
</parent>
  <modelVersion>4.0.0</modelVersion>
  <groupId>customModule</groupId>
  <artifactId>dbunit</artifactId>
  <dependencies>
    <dependency>
        <groupId>com.myComp.user</groupId>
        <artifactId>user-portal</artifactId>
        <version>1.15</version>
        <scope>compile</scope>
        <type>war</type>
    </dependency>
  </dependencies>
</project>

user-portal POM having utils as dependency

 <dependencies>
    <dependency>
        <groupId>com.myComp.user.utils</groupId>
        <artifactId>utils</artifactId>
        <version>1</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
 </dependencies>

But utils classes are not visible under customModule. I am not sure why transitive dependencies/classes are not visible here ?

scott miles
  • 1,511
  • 2
  • 21
  • 36
  • The problem is simply that you are using a war as dependency which is by default not transitive. You should change that `war` module accordingly to produce a separate jar file which is described in the answer. – khmarbaise Mar 18 '18 at 09:38
  • @khmarbaise Please see mine comment under answer – scott miles Mar 18 '18 at 10:11

1 Answers1

1

When depending to war packaging, classes inside the war is not visible. You should add <attachClasses>true</attachClasses> to your war plugin in user-portal project. This will produce both war and a jar with the classes.
In the dependent project you should depend to <classifier>classes</classifier> instead of war.

inside user-portal pom.xml

 <build>
    ...
      <plugins>
      ...
         <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.0</version>
          <configuration>
            <attachClasses>true</attachClasses>
          </configuration>
        </plugin>
      ...
      </plugins>
    ...
    </build>

customModule pom.xml

   <dependency>
        <groupId>com.myComp.user</groupId>
        <artifactId>user-portal</artifactId>
        <version>1.15</version>
        <classifier>classes</classifier>
    </dependency>

As a side note, default scope is compile you don't have to specify it.

Source = https://pragmaticintegrator.wordpress.com/2010/10/22/using-a-war-module-as-dependency-in-maven/

miskender
  • 7,460
  • 1
  • 19
  • 23
  • With the changes you suggested I see `user-portal-1-classes` generated but that jar does not contain the further dependencies(direct and transitive) on which my `customModule` is dependent ? – scott miles Mar 18 '18 at 10:09
  • @scottmiles Yes It wont contain dependency classes, if you want dependencies also you should add maven-assembly-plugin to. war plugin will create your war, assembly will create a jar with dependencies.(assembly plugin can also create war but not recomended for that use.)http://maven.apache.org/plugins/maven-assembly-plugin/usage.html – miskender Mar 18 '18 at 11:04
  • 1
    Yes you are right. But somehow my eclipse is able to resolve transitive deps even without making executable/fat jar. I believe eclipse is able to resolve all dependent projects through `classifier` attribute in pom – scott miles Mar 18 '18 at 11:45