bensassi mohammed
bensassi mohammed

Reputation: 31

Spring Boot Maven Plugin – Exclude all dependencies

In my current project I'm using spring boot i want to exclude all dependencies.

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>1.3.3.RELEASE</version>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <mainClass>a.b.testClass</mainClass>
        <layout>ZIP</layout>
          <excludeArtifactIds>*</excludeArtifactIds>
    </configuration>
</plugin>

Upvotes: 2

Views: 4538

Answers (2)

Mag
Mag

Reputation: 379

Ugly solution that seems to work is to put includes with not existing artifact:

<configuration>
    <layout>ZIP</layout>
    <includes>
        <include>
            <groupId>abc</groupId>
            <artifactId>abc</artifactId>
        </include>
    </includes>
</configuration>

Works on version 1.3.3 but there is not guarantee it won't change in next versions.

Or, you can package everything yourself, there are instructions for ant: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html#howto-build-an-executable-archive-with-ant that can give you list of steps that you need to apply in maven. So:

  1. Include Main Class and Start Class in manifest:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
    
        <configuration>
            <archive>
                <manifest>
                    <mainClass>org.springframework.boot.loader.PropertiesLauncher</mainClass>
                </manifest>
                <manifestEntries>
                    <Start-Class>your.package.YourMainClass</Start-Class>
                </manifestEntries>
            </archive>
        </configuration>
    </plugin>
    
  2. Skip adding dependencies in lib directory.

  3. Add spring boot loader classes to the root: First you need dependency:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-loader</artifactId>
        <version>1.3.3.RELEASE</version>
    </dependency>
    

    Then you need to unpack it:

    <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
    
        <executions>
            <execution>
                <phase>process-sources</phase>
    
                <goals>
                    <goal>unpack</goal>
                </goals>
    
                <configuration>
                    <artifactItems>
                        <artifactItem>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-loader</artifactId>
                            <outputDirectory>${project.build.directory}/classes</outputDirectory>
                        </artifactItem>
                    </artifactItems>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    There might be a better way to put loader classes in root, but this works ok for my project.

Upvotes: 2

P S M
P S M

Reputation: 1161

You can try this one.

<configuration>
      <excludes>
        <exclude>
          <groupId>*</groupId>
          <artifactId>*</artifactId>
        </exclude>
      </excludes>
    </configuration>

Upvotes: -1

Related Questions