-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Allow provided and optional dependencies to be exclude when building a uber jar with Maven #13289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
That's the Maven textbook definition but it does not apply to what the Can you share more details please? |
One other example (besides annotations) is we have dependencies with Although some parts could probably be streamlined to not use |
You can unpack and process dependencies with the The reason why I insist so much is because it's part of the user experience you get with Spring Boot. Anything that is required that way means that it's harder for you to run the application from your IDE. |
Perhaps they shouldn't. However, this is reality of the build we have right now and it works in maven with every other plugin and worked like this before for every project we have. Perhaps we could change that, but that would take some time and would not be done in a day. Since you're mentioning IDE, the current build works perfectly in IntelliJ IDEA and we aren't really using other IDEs, so I don't know how other IDEs handle this. |
We've discussed at the team call and given that |
pretty silly I'd say |
we are running into the same issue where spring-boot plugin pulling in the provided scope 'javax.ws.rs-api' which requires jersey-common at runtime At the same time we str also using the thin boot, but need the option to switch to fat jar at build time, this means we need 2 layout factories. Spring boot plugin bails with java.lang.IllegalStateException: No unique LayoutFactory found The layout same sample is not trivial ( sorry about my ignorance), not able to get it working yet. if anyone has already implemented the customer factory, I would like to have a look Also note: thin-boot does not include provided scope, so I am convinced that spring-boot-plugin violates maven spec/convention and best to provide an option for user to disable provided scope inclusion |
i am able to get custom layout working and use 2 maven profiles, one build by default with thin boot and another one with activation
quite complex. But it works |
Using configuration exclusion seems to be a much simpler solution. Not sure whether this fits all your other use cases, though. <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin> |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I wound up here because I was wondering why Spring Boot packages lombok into my fat jar. Excluding artifacts individually may be okay in some cases, but configuration to opt-out of packaging all provided-scope artifacts sounds like a good idea to me. Explicit excludes are simply not maintainable. |
Found a far more painful annotation-processing example:
|
This comment has been minimized.
This comment has been minimized.
@chanseokoh the issue tracker is not the right place to have such conversation. There is a section with some examples that shows you what the plugin does at the moment and how to configure it to do so. If those are not giving you enough information, feel free to raise a separate issue or, better yet, create a PR to improve the documentation. |
Is someone working on this issue or any update ? Unfortunately, I still am facing problems with exclusion (with provided scope) or wildcards. |
It has been several months since we've heard from @pgerhard so I doubt that anyone's working on it. I'll update the issue's assignment to reflect that. |
Is there any latest update to this issue? |
@Gyanaranjan1993 Nothing beyond what you can see in the issue. |
Oh my god! I just fund this issue... I was debugging for hours and and was questioning my sanity. This is really bad, I cannot think of any valid reason why an optional dependency should be packed in the spring boot fat jar. I can see a point for provided scope because of the fat jar thing but it still is a violation of the maven spec/convention so there should be a big, prominent warning in the README regarding the current default behavior. |
No it isn't. An optional dependency is one that this project uses for build/deploy, but if you depend on this project then it's not included by default. Building a fat jar is for deploying this project. Nothing else should be using the fat jar as a dependency. If optional dependencies weren't included in the build, there would be no point adding them to the pom in the first place, So why are you if you don't want them? |
Yes it is a violation. please read the official maven docs:
https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html I would agree with you if we would be talking about the |
We intend to change the default behavior with optional dependencies. That change is being tracked by #25403. In the meantime, I think we could update this section of the documentation. I've opened #34636 for that. |
This is how they behave. It has nothing to do with the fat jars. |
No that is currently not the case. Let me give you an example: Let's assume you write a library to provide a database specific feature. To implement the feature you need to access die classes in the jdbc driver. However you want support multiple databases. So instead of creating a additional module for each driver you only implement one module with all drivers you want to support as an optional dependency. In such a case you absolutely don't want the final application to contain all optional jdbc drivers. Instead you expect the developer of the final application to add the driver he/she is actually using as a dependency. |
This should already work exactly as you want. The fat jar will not include optional transitive dependencies, only optional dependencies that are declared directly in its own pom. |
That library will not be building a Spring Boot fat jar, so there's no problem. |
Yes you're right I checked again and was totally wrong in that regard. I was mislead by a dependency that was marked as optional in my library but was actually also a transitive dependency from another (not optional) dependency. That's why it was packaged in the fat jar. 🙃 Sorry for that. However I still think it would be a good to have a solution to mark a direct dependency as "this should not land in the fat jar" without the need to exclude it in the spring boot plugin. (for annotation processors and stuff like that) |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
I am really curious why dependencies with scope provided are included. We have a division pom where we included the following in dependencyManagement:
We use |
When you're building a fat jar, there's no runtime environment like Tomcat or Jetty to provide the dependencies. The jar itself needs to contain all of the dependencies that aren't part of the JDK. For this reason, provided dependencies are included as there's nothing else to provide them. |
For us there is a runtime, we use spring-boot starters and these then include stripped-down versions of tomcat and jetty. |
In that case, it's not clear to me how or why you're using Spring Boot's fat jar support which is intended to produce a standalone artifact that does not require a runtime other than the JVM. |
Maybe the wording does confuse me here? We build spring-boot applications as executable fat jar and package these as Debian DPKG (depending on a JRE) resp. put the same "fat" jar into a Docker image which only contains a JRE.
Alternatively these may be started with |
This comment was marked as outdated.
This comment was marked as outdated.
Dropping in my insight why it would be great to get this (or technically the In Vaadin projects we have these certain developement time extensions, which are essentially brought in by a dependency So, pretty please, consider taking this (or at least the optional part) to your TODO list. It would pave way to make Vaadin builds look cleaner and we could remove some code from Spring Initializr 🤓. I guess there might be some rare regressions, but I guess those apps are today working "accidentally" as there is no good reason today to have Gradle users are lucky with their The related Vaadin issue: vaadin/flow#17737 |
I was trying to make a (somewhat ugly) workaround by making another plugin (that would finally be vaadin plugin) adjust the excludes, but I didn't come up with any other way but properties to defined excludes from another plugin. But then I couldn't figure out how to configure excludes via property. I guess this tiny enhancment/fix is missing (and probably can be handy for others for less ugly hacks) 🤔 #39837 |
I stumbled upon #413 when trying to resolve exactly the same problem. We're using some
provided
artifacts and don't want them to end up in the final deliverable. This is exactly 100% according to maven definition ofprovided
scope (i.e., available on the compile and test classpaths, but not at runtime).Case in point, recommended usage of Lombok annotations is via
provided
scope. But that's just one example. We're using many other dependencies that are essentially build-time dependencies, not runtime ones. (And not just annotations that can be wired viaannotationProcessorPaths
property mentioned in #10539.) Trying to switch to spring-boot-maven plugin, but this results in huge repackaged jar containing a lot of unnecessary junk due to transitive dependencies of provided artifacts.TLDR: I'd really appreciate an
includeProvidedScope=false
option (similar toincludeSystemScope
) for people who know what they are doing, so that I can configure this in just one place for all projects and don't need to duplicate a list of dependencies as excludes in the plugin config.The text was updated successfully, but these errors were encountered: