1

I want to package the spring boot jar without the javafaker dependency. I am using the Javafaker dependency and want it to be loaded only during dev time.

<dependency>
  <groupId>com.github.javafaker</groupId>
  <artifactId>javafaker</artifactId>
  <version>1.0.2</version>
  <scope>provided</scope>
</dependency>

Even after adding the scope as provided, the jar is packaged as part of the final jar file. How can I exclude the dependency in the final build.

zilcuanu
  • 3,451
  • 8
  • 52
  • 105

1 Answers1

2

It seems that this is done intentionally by the Spring Boot team

From https://github.com/spring-projects/spring-boot/issues/413 :

The packaging of provided scoped jars is intentional. The reason for this is that many developers are used to adding things like servlet-api as provided. Since there won’t be a servlet container to actually “provide” the dependency we package it inside the JAR.

The only way to ensure that it doesn't end up in your JAR file is to use the spring boot maven plugin configuration and exclude it there.

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>com.github.javafaker</groupId>
                            <artifactId>javafaker</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
ddewaele
  • 22,363
  • 10
  • 69
  • 82
  • "Since there won’t be a servlet container to actually “provide” the dependency we package it inside the JAR" - IMO, Phil Webb was wrong there: tomcat-embed jar does contain servlet-api, jetty doesn't, however that would be more elegant to ask eclipse developers to publish embeddable artifact as well. – Andrey B. Panfilov Dec 18 '22 at 14:00