3

I have the following maven structure

parent POM.XML
 - common/pom.xml
 - search/pom.xml

Search module is not able to get common module classes when i do mvn clean install on search module I get package de.test.common does not exists. I even ran mvn clean install on parent platform but no success. common module is building fine.

<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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>de.test.search</groupId>
    <artifactId>search</artifactId>
    <packaging>jar</packaging>
    <parent>
        <groupId>de.test.platform</groupId>
        <artifactId>platform</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <properties>
        <app-name>search</app-name>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>
        <dependency>
            <groupId>de.test.common</groupId>
            <artifactId>common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>searchdev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                    <optional>true</optional>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <!-- log configuration -->
                <logback.loglevel>DEBUG</logback.loglevel>
            </properties>
        </profile>
        <profile>
            <id>searchprod</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.heroku.sdk</groupId>
                        <artifactId>heroku-maven-plugin</artifactId>
                        <version>1.0.3</version>
                        <configuration>
                            <appName>${app-name}</appName>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <!-- log configuration -->
                <logback.loglevel>INFO</logback.loglevel>
            </properties>
        </profile>
    </profiles>
</project>

common 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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>de.test.common</groupId>
    <artifactId>common</artifactId>
    <packaging>jar</packaging>
    <parent>
        <groupId>de.test.platform</groupId>
        <artifactId>platform</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <properties>
        <app-name>common</app-name>
    </properties>
    <profiles>
        <profile>
            <id>commondev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                    <optional>true</optional>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <!-- log configuration -->
                <logback.loglevel>DEBUG</logback.loglevel>
            </properties>
        </profile>
        <profile>
            <id>commonprod</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.heroku.sdk</groupId>
                        <artifactId>heroku-maven-plugin</artifactId>
                        <version>1.0.3</version>
                        <configuration>
                            <appName>${app-name}</appName>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <!-- log configuration -->
                <logback.loglevel>INFO</logback.loglevel>
            </properties>
        </profile>
    </profiles>
</project>

enter image description here

I think i have the same problem mentioned here

maven compilation failure

Found the problem but not the cause

I removed the following dependency and everything is okay

          <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

after removing the plugin the jar is build in a different structure. When spring boot plugin was there the whole content was inside BOOT-INF folder which i think was the cause, not sure though... need expert opinion here.

Community
  • 1
  • 1
Saurabh Kumar
  • 16,353
  • 49
  • 133
  • 212

2 Answers2

2

The easiest way to solve this is through a so called reactor project, where you build all dependent modules with the parent pom. To that end, add the following code to your parent POM:

<modules>
  <module>common</module>
  <module>search</module>
</modules>

Now, build the parent pPOM and your entire build should work. Also, don't use explicit versions in the child projects, only inherit the version from the parent POM (I think you're good there). If you reference dependencies from the same project reactor, use the version ${project.version}.

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
1

Found the solution. May be somebody will find it useful.

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <classifier>exec</classifier>
                </configuration>
            </plugin>
        </plugins>
    </build>
Saurabh Kumar
  • 16,353
  • 49
  • 133
  • 212
  • What it does is appending the specified classifier at the end of Spring Boot Jar while keeping the non-Boot Jar as is. This way the dependent module can get its dependency. Spring Boot Jar is repackaged in a way that the dependent module cannot load a repackaged jar's classes. – xli Jan 31 '19 at 21:03