Skip specified attached artifacts from deploy - #3
Conversation
|
First thanks for trying to contribute...(BTW: Can you read the informations about contribution etc. here https://github.com/apache/maven-help-plugin we have not yet added the information to all plugin repositories on github).. Maybe I misunderstand your idea...but if I have configured maven-shade-plugin to attach the artifact why should I skip deploying the artifact? Can you give an example of a real life scenario where this makes sense ? |
|
So added some information https://github.com/apache/maven-deploy-plugin/tree/MDEPLOY-239 ... |
|
Thank you for sharing and introducing informations about contribution on the project. I'll follow all the indicated procedure for possible future contributions. About needs that made me look for this solution I exposed my specific scenario as solution on the following thread on stackoverflow: Basically I needed to attach an uber jar artifact on my maven module without versioning it on my repository. Reason is that this artifact is then included as dependency into another module and this is the one uploaded on repository ( this will allow me to exclude transitive dependencies I had instead into the skipped one ). Moreover I found also that other people searched for this solution according to their needs. In general I think it could be useful for all that scenarios where user want to generate attached artifacts and just use these locally for some reason without uploading them on repository. |
|
Another practical use case, due to the constraints of our CI/CD system some of our projects use Apache Maven as the overarching build tool but use plugins to invoke other tools - Then for ease of integration testing within our large multi-modules builds we have these plugins attach Maven artifacts as well, this lets us then have other modules depend on those artifacts explicitly to enforce required module build order and that the developer activated the right profile. BUT we don't actually want to deploy these attached artifacts because the original artifacts e.g. the Docker images themselves are going to get deployed by non-Maven post-processing steps to their own appropriate repositories provided as part of our CI/CD system. TL;DR We use Maven to build non-Maven artifacts (e.g. Docker images) that don't want/need to be deployed to our Maven repository |
|
another usecase is i have a shaded artifact which i don't want to deploy to remote repository even i skip the main project artifact to deploy the rpm artifact but still the shaded artifact is deployed there! there must be a way to skip base in classifier. |
|
In my case, I produce an |
|
My use-case is that I generate a Spring Boot fat JAR with I can skip attaching the fat JAR (the plugin supports I just want a simple way to tell deploy-plugin, "don't deploy something". I don't want to go down a rabbit hole trying to stop stuff being attached in the first place. I could imagine a world where someone wants an artifact to be install-able but not deploy-able. In which case, not attaching the artifact is not a solution. @khmarbaise Can you please comment on this? You wanted a real-world use-case, and 5 people have now given you theirs. It's disappointing that a PR has been ready to go for 6 years and is still sitting here. I checked through it and it looks like a high-quality change. It has tests and updates to documentation. I'm happy to fix the conflicts. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds support to selectively skip deployment of specified attached artifacts in the Maven Deploy Plugin.
Changes:
- Introduces a new
skipAttachedArtifactsplugin configuration parameter. - Removes matching attached artifacts from the deploy set and logs skipped artifacts.
- Adds/updates unit tests and site FAQ documentation for the new behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java | Adds skipAttachedArtifacts configuration and removal logic before deployment |
| src/main/java/org/apache/maven/plugins/deploy/AttachedArtifact.java | New configuration POJO to identify attached artifacts to skip |
| src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java | Adds tests for success/failure behavior when excluding attached artifacts |
| src/site/fml/faq.fml | Documents how to configure skipping attached artifacts |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @Mojo( name = "artifact" ) | ||
| public class AttachedArtifact |
| @Parameter( property = "groupId" ) | ||
| private String groupId; |
| @Parameter( property = "artifactId" ) | ||
| private String artifactId; |
| @Parameter( property = "version" ) | ||
| private String version; |
| @Parameter( property = "packaging" ) | ||
| private String packaging; |
| @Parameter( property = "classifier" ) | ||
| private String classifier; |
| final List<Artifact> attachedArtifacts = pdr.getProject().getAttachedArtifacts(); | ||
| if ( skipAttachedArtifacts != null ) | ||
| { | ||
| for ( final AttachedArtifact attachedArtifactToSkip : skipAttachedArtifacts ) | ||
| { | ||
| final Artifact toSkip = attachedArtifactToSkip.checkIfExists( attachedArtifacts ); | ||
| attachedArtifacts.remove( toSkip ); | ||
| getLog().info( "Skipping artifact [" | ||
| + toSkip | ||
| + "]" ); | ||
| } | ||
| } |
| public void testDeployWithNotExistingAttachedArtifactsExcluded() | ||
| throws Exception { |
| </answer> | ||
| </faq> | ||
| <faq id="skipAttachedArtifacts"> | ||
| <question>I don't want to deploy some attached artifact on a specific module. Can I skip deployment for specific attached artifacts?</question> |
Suppose you have differents artifacts attached on a single Maven module. For example:
I've worked on my fork project in order to allow to specify artifacts to skip deploy for.
Here the usage example:
Implementing feature I took care of:
As result you will have the following output during execution:
[INFO]
[INFO] --- maven-deploy-plugin:3.0.3-SNAPSHOT:deploy (default-deploy) @ cc-manager4j ---
[INFO] Skipping artifact [com.group.test:test-artifact:jar:shaded:1.0-SNAPSHOT]
If attached artifact to skip doesn't exists the plugin will fail the execution:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:3.0.3-SNAPSHOT:deploy (default-deploy) on project cc-manager4j: No attached artifact com.group.test:test-artifact:zip:shaded:1.0-SNAPSHOT to exclude from deploy found -> [Help 1]
[ERROR]