2

I have several maven modules: common, A, B, C. I wonder if it is possible to include the common module as a compilation unit in the other three modules.

I tried this by declaring the common module with

<packaging>pom</packaging> and in module A, I included common as a dependency:

<dependencies>
    <dependency>
        <groupId>group.id</groupId>
        <artifactId>common</artifactId>
        <version>1.0</version>
    </dependency>
</dependencies>

However, when I do

mvn clean compile

on the whole project, there is an error thrown when compiling module A:

Could not transfer artifact group.id:common:jar:1.0 from ..

It is trying to download the get the common dependency from the maven remote repository. I do not want to do that: I do not want to install common module on the local or remote repository. I just want to compile common and include the compiled classes in the other modules.

It is possible to do that? I am also using spring boot.

Alex
  • 971
  • 1
  • 9
  • 23
  • The common contains some kind of common code which should be used in other modes. If yes than you need to define packaging `jar` or just omit the packaging to create a jar file which contains the java classes etc. – khmarbaise Jun 30 '17 at 08:11
  • What is the version being built? Probably more a "X.Y.Z-SNAPSHOT" than "1.0". – Tome Jun 30 '17 at 08:17
  • If I use packaging _jar_ I receive an error from spring boot plugin because it is unable to find a main class for the module. The idea is that _common_ will not contain any main class. It is just an internal library for the other modules in the same project. That is why I do not want to install it on maven remote repo, and rather I want to include it as a compilation unit for the other modules. – Alex Jun 30 '17 at 11:53
  • 1
    At least, common module should have a "JAR" packaging, but not being configured to be repackaged by Spring Boot Maven plugin. – Tome Jun 30 '17 at 14:33
  • @Tome, your suggestion works just fine. I also followed this post in order to configure spring boot to skip repackaging for that module: [Spring boot with maven multi module project](https://stackoverflow.com/questions/34390172/spring-boot-with-maven-multi-module-project). You can provide an official answer to this question so I can validate it, or however you want. The idea is that your answer is correct and your suggestions are sufficient. – Alex Jul 03 '17 at 07:05

0 Answers0