Maven: The packaging for this project did not assign a file to the build artifact

前端 未结 8 1566
误落风尘
误落风尘 2020-11-30 18:25

I\'m using Maven 3.0.3 on Mac 10.6.6. I have a JAR project and when I run the command \"mvn clean install:install\", I\'m getting the error,

[ERROR] Failed         


        
相关标签:
8条回答
  • 2020-11-30 19:03

    TL;DR To fix this issue, invoke packaging plugin before, e.g. for jar packaging use maven-jar-plugin , as following:

    mvn jar:jar install:install
    

    Or

    mvn jar:jar deploy:deploy 
    

    If you actually needed to deploy.

    Gotcha This approach won't work if you have multi-module project with different packagings (ear/war/jar/zip) – even worse, wrong artifacts will be installed/deployed! In such case use reactor options to only build the deployable module (e.g. the war).


    Explanation

    In some cases you actually want to run directly a install:install or deploy:deploy goal (that is, from the maven-deploy-plugin, the deploy goal, not the Maven deploy phase) and you would end up in the annoying The packaging for this project did not assign a file to the build artifact.

    A classic example is a CI job (a Jenkins or Bamboo job, e.g.) where in different steps you want to execute/care about different aspects:

    • A first step would be a mvn clean install, performing tests and test coverage
    • A second step would be a Sonarqube analysis based on a quality profile, e.g. mvn sonar:sonar plus further options
    • Then, and only after successful tests execution and quality gate passed, you want to deploy to your Maven enterprise repository the final project artifacts, yet you don't want to re-run mvn deploy, because it would again execute previous phases (and compile, test, etc.) and you want your build to be effective but yet fast.

    Yes, you could speed up this last step at least skipping tests (compilation and execution, via -Dmaven.test.skip=true) or play with a particular profile (to skip as many plugins as possible), but it is much easier and clear to simply run mvn deploy:deploy then.

    But it would fail with the error above, because as also specified by the plugin FAQ:

    During the packaging-phase all gathered and placed in context. With this mechanism Maven can ensure that the maven-install-plugin and maven-deploy-plugin are copying/uploading the same set of files. So when you only execute deploy:deploy, then there are no files put in the context and there is nothing to deploy.

    Indeed, the deploy:deploy needs some runtime information placed in the build context by previous phases (or previous plugins/goals executions).

    It has also reported as a potential bug: MDEPLOY-158: deploy:deploy does not work for only Deploying artifact to Maven Remote repo

    But then rejected as not a problem.

    The deployAtEnd configuration option of the maven-deploy-plugin won't help neither in certain scenarios because we have intermediate job steps to execute:

    Whether every project should be deployed during its own deploy-phase or at the end of the multimodule build. If set to true and the build fails, none of the reactor projects is deployed. (experimental)

    So, how to fix it?
    Simply run the following in such a similar third/last step:

    mvn jar:jar deploy:deploy
    

    The maven-jar-plugin will not re-create any jar as part of your build, thanks to its forceCreation option set to false by default:

    Require the jar plugin to build a new JAR even if none of the contents appear to have changed. By default, this plugin looks to see if the output jar exists and inputs have not changed. If these conditions are true, the plugin skips creation of the jar.

    But it will nicely populate the build context for us and make deploy:deploy happy. No tests to skip, no profiles to add. Just what you need: speed.


    Additional note: if you are using the build-helper-maven-plugin, buildnumber-maven-plugin or any other similar plugin to generate meta-data later on used by the maven-jar-plugin (e.g. entries for the Manifest file), you most probably have executions linked to the validate phase and you still want to have them during the jar:jar build step (and yet keep a fast execution). In this case the almost harmless overhead is to invoke the validate phase as following:

    mvn validate jar:jar deploy:deploy
    

    Yet another additional note: if you have not jar but, say, war packaging, use war:war before install/deploy instead.

    Gotcha as pointed out above, check behavior in multi module projects.

    0 讨论(0)
  • 2020-11-30 19:04

    you must clear the target file such as in jar and others In C: drive your folder at .m2 see the location where it install and delete the .jar file,Snaphot file and delete target files then clean the application you found it will be run

    0 讨论(0)
提交回复
热议问题