Spring-boot: exclude packaging dependencies

I am working on a spring loading project (Project A), which will be included in other projects (Project B, Project C ...). I have several dependencies in Project A, but in the project importing Project A, some or only one may be required. I am trying to find a way to eliminate jar dependencies during the packaging of Project A, so that the required ones will be provided to Project B at run time. I would like to have the dependencies available when Project A runs independently for testing purposes.

Already tried the following

I tried using:

<scope>provided</scope>
<optional>true</optional>

However, the baths end in the final artifact.

Also tried adding the following to spring-boot-maven-plugin

           <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <excludeArtifactIds>spring-boot-starter-redis</excludeArtifactIds>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

spring -boot, .

+4
2

, JEE-. jar, API , JEE-.

jar, Boot, .

, , . , , , JDBC, . , , JEE-. spring -boot-starter-tomcat spring -boot-starter-jdbc. pom.xml:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
    <scope>provided</scope>
</dependency>
<dependency>
  <groupId>com.oracle</groupId>
  <artifactId>ojdbc7</artifactId>
  <scope>provided</scope>
</dependency>

, jar/war, spring boot maven , lib, /.

JEE, , . , spring boot maven , :

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
      <mainClass>${start-class}</mainClass>
      <classifier>exec</classifier>
  </configuration>
</plugin>

, maven :

  • jar/war , .
  • , _exec.jar/.war, lib java -jar

, A, B, A .

Project A, , IDE, waven2 pom.xml.

+6

B pom.xml :

  <dependencies>
    ....
    <dependency>
        <groupId>com.example</groupId>
        <artifactId>projectA</artifactId>

        <exclusions>
            <exclusion>
                <groupId>com.foo.bar</groupId>
                <artifactId>baz</artifactId>
            </exclusion>
            ....
        </exclusions>
    </dependency>
    .....
   </dependencies>
-1

All Articles