If I just run the Maven goal deploy:deploy
this will result in an error.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-cli) on project [...]: The packaging for this project did not assign a file to the build artifact -> [Help 1]
I get to that in a minute. First I have to explain what I want to do. My goal is a sequenced build pipeline like this:
- Compile code, run tests, generate jar files (basically a
mvn clean package
). - Run a static code analysis.
- Assemble artifacts (zip archives, container images, etc.) using the result from step 1.
- Deploy artifacts to repository using the result from step 3.
- ...
Each of these steps is supposed to continue the build pipeline even further with the result of the previous step and without(!) repeating the previous steps. In addition, some higher steps don't need to run every time. For example, the most important thing for a typical feature or bugfix branch is the code compilation, the test execution and the code analysis. This will give the developers the necessary feedback in case they broke something. There is no need to actually assemble the artifacts, because there is no point in deploying them somewhere. Only for a small number branches (like master) and for tags it makes sense to run everything.
Here is the problem: Maven gets in the way of that. Maven always needs to run everything. Lets say I do something like this (simplified):
$ mvn clean package
$ mvn deploy
The first command will satisfy the goal of step 1. The second command will do the exact same thing plus the actual deployment.
Simply put: I would compile my code twice. I would run the tests twice. I would create the jar files twice. But all that was already done with the first command. All the jar files are already there (in the target folder). I just want Maven to pick them up. I don't want Maven to repeat step 1.
Plus, I don't want to only run an all-in-one command like mvn deploy
in a single all-in-one build pipeline step because it will prevent me from splitting my build process into logical steps. However, I still like to use the deploy plugin anyway, because it can make the decision which repository it has to use (snapshot, or release) based on the version number and the distribution management configuration. I don't want to "re-implement" that logic in my build script. For that reason deploy:deploy-file
isn't an option, because that goal can't do that.
That's why I am looking for a way to replace the second command (mvn deploy
) with something like this:
mvn clean deploy:deploy
This would only run the actual deployment. The problem: the previous phases didn't run. That's why I get the error (I showed you above).
Unfortunately Maven ignores the ready-to-go jar files in the target folder and aborts with an unable-to-find-artifact error. Maven seems only to recognize the artifacts which where internally attached during the execution of the previous phases.
This is also true for other goals, like mvn spring-boot:repackage
, which kind of belongs in the assemble step. So I have to find a general solution. I was hoping that there is a way to somehow attach the files (manually) along with a command like mvn deploy:deploy
so that I don't need to redundantly execute previous phases.
Do you have any idea how to solve that?
Is there a way to resume the build from a specified phase?
Are there alternative plugins, who could help?
A little outside the box: Is this easier to solve using Gradle?