;tldr I want a repackaged jar file with all optional dependencies removed.

Details: Using <optional>true</optional> is a great way to improve developer experience. For example, I have an optional dependency to an helper artifact that sets up some testcontainers for running the service locally. Obviously, I don't need the helper artifact in the repackaged jar that will be used for production.

What I want to achieve in detail: 1. Include a single helper artifact like

<dependency>
    <groupId>com.myproject.helper</groupId>
    <artifactId>local-env-helper</artifactId>
    <scope>provided</scope>
    <optional>true</optional>
</dependency>

This helper has a transitive dependency to, for example, org.testcontainers and some magic that automatically sets up containers when the artifact is available on runtime class path. 2. I want this artifact and its transitive dependencies to end up on my classpath during development in my IDE 3. I don't want this artifact and its transitive dependencies to end up in my final repackaged jar

I'm not quite sure whether the optional flag is inherited by all transitive dependencies so that it could actually be used for filtering here. In this example it would be sufficient to exclude provided-scoped dependencies. But I haven't found a way to do that.

Comment From: snicoll

@skuzzle provided scope with optional looks a bit odd to me. Reading your description you could easily achieve this by having a dev profile and move those dependencies there. Your IDE should allow you to easily enable the dev profile there so that it is transparent for you.

As for excluding those dependencies, I believe this is a duplicate of #16563 and this issue now links to it so that we can keep track of the use case you've described when we get to it.