0

Doing a repackage with Maven spring boot plugin didnt help.

  1. Tried cleaning the .m2 folder.
  2. Built the project both from sts and command line.
  3. Added Component Scanners to scan entity but fails at maven build itself.
  4. Added Spring Boot Maven Plugin to repackage as executable jar option, nothing seems to be helping.

Parent pom contains the spring boot starter

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.6.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
  </parent>

And the following modules

<modules>
    <module>client-data</module>
    <module>eureka-server</module>
    <module>eureka-client-service-1</module>
    <module>eureka-client-service-2</module> 
 </modules>

eureka-client-service-1 and eureka-client-service-2 have client-data as dependency.

Since client-data is a spring-boot project with package type jar, have added the following piece of code to create an uber jar in the client-data's pom.xml

     <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <classifier>exec</classifier>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Still doing a mvn clean install -amd -e ends up in follwing error

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project eureka-client-service-1: Compilation failure: Compilation failure:
[ERROR] /C:/Users/balaji/trashcan/pcf-eureka-show-case/eureka-client-service-1/src/main/java/org/balaji/java/jee/pcf/eureka/client/service_1/boundary/EurekaClientEmployeesServiceEndpoint.java:[16,65] package org.balaji.java.jee.pcf.eureka.client.data.controller does not exist
[ERROR] /C:/Users/balaji/trashcan/pcf-eureka-show-case/eureka-client-service-1/src/main/java/org/balaji/java/jee/pcf/eureka/client/service_1/boundary/EurekaClientEmployeesServiceEndpoint.java:[17,61] package org.balaji.java.jee.pcf.eureka.client.data.entity does not exist
[ERROR] /C:/Users/balaji/trashcan/pcf-eureka-show-case/eureka-client-service-1/src/main/java/org/balaji/java/jee/pcf/eureka/client/service_1/boundary/EurekaClientEmployeesServiceEndpoint.java:[27,5] cannot find symbol
[ERROR] symbol:   class OrganizationDataFixtureAdapter
[ERROR] location: class org.balaji.java.jee.pcf.eureka.client.service_1.boundary.EurekaClientEmployeesServiceEndpoint
[ERROR] /C:/Users/balaji/trashcan/pcf-eureka-show-case/eureka-client-service-1/src/main/java/org/balaji/java/jee/pcf/eureka/client/service_1/boundary/EurekaClientEmployeesServiceEndpoint.java:[42,32] cannot find symbol
[ERROR] symbol:   class Employee
[ERROR] location: class org.balaji.java.jee.pcf.eureka.client.service_1.boundary.EurekaClientEmployeesServiceEndpoint
BalaajiChander
  • 139
  • 3
  • 21
  • 1
    Modules aren't dependencies. Create another module which really adds everything as a dependency and shade all in there. You can't use the `parent` for the compilation of all together. – CodeMatrix Jul 17 '19 at 06:33
  • A Spring boot jar is used to contain a complete runnable application. It's not supposed to be used as a library. Its content is a custom classloader and launcher and a bunch of embedded jars. If you want to use a project A as a dependency of another project B, then A shouldn't be a SPring Boot application packaged with the Spring Boot plugin. It should be a plain old library, packaged as a plain old jar. – JB Nizet Jul 17 '19 at 06:37
  • Thanks @JB Nizet. Since this being a multi module maven project the behaviour is inherited from parent pom, since i am using spring-boot-starter. Is there any way I can remove the spring-boot behaviour without changing the project structure. – BalaajiChander Jul 17 '19 at 06:54
  • Thanks @ CodeMatrix. The parent project is simply a pom project and the child modules are deeply packed, mean nested modules. – BalaajiChander Jul 17 '19 at 06:57
  • 1
    A spring boot starter is a library. I guess you're talking about the spring boot **plugin**. I have no idea: I don't use Maven. But I guess that instead of applying the Boot plugin by default and trying to remove it, I wouldn't apply it by default and only add it on **the** project which is actually a Spring Boot application. – JB Nizet Jul 17 '19 at 06:57

1 Answers1

1

For the question of "Is there any way I can remove the spring-boot behavior without changing the project structure."

=> You can override the spring-boot-maven-plugin behavior in your child pom file.

Referring here: How to add a dependency to a Spring Boot Jar in another project?

Spring Boot 1.x

  <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>1.5.20.RELEASE</version>
    <executions>
      <execution>
        <goals>
          <goal>repackage</goal>
        </goals>
        <configuration>
          <classifier>exec</classifier>
        </configuration>
      </execution>
    </executions>
    ...
  </plugin>

Spring Boot 2.x If you are using spring-boot-starter-parent, the repackage goal is executed automatically in an execution with id repackage. In that setup, only the configuration should be specified as shown in the following example:

  <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
      <execution>
        <id>repackage</id>
        <configuration>
          <classifier>exec</classifier>
        </configuration>
      </execution>
    </executions>
    ...
  </plugin> 
Y Le
  • 11
  • 2