Parent POM is not flattened when deployed to Nexus - maven

I have a multi-module Maven project where the project version is set via the revision variable.
<groupId>pricing</groupId>
<artifactId>pricing-backend-pom</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<properties>
<revision>3.0.7</revision>
</properties>
<modules>
<module>pricing-backend-war</module>
<module>pricing-backend-model</module>
<module>pricing-backend-client</module>
</modules>
<build>
<plugins>
<!-- flatten before deploy. removes $revision -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.2.7</version>
<configuration>
</configuration>
<executions>
<!-- enable flattening -->
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<!-- ensure proper cleanup -->
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
During the Gitlab build, the project is deployed to a Nexus repository. Each module and the parent appear in Nexus but only the modules appear to be flattened. The module POMs each contain <version>3.0.7</version> but the parent POM still contains <version>${revision}</version>.
I find it difficult to understand why the parent is deployed differently to the modules. I have checked the build logs but cannot see any indication that the parent is handled in a different way.
The parent POM taken from Nexus:
<groupId>pricing</groupId>
<artifactId>pricing-backend-pom</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<properties>
<revision>3.0.7</revision>
...
A module POM:
<groupId>pricing</groupId>
<artifactId>pricing-backend-client</artifactId>
<version>3.0.7</version>
<dependencies>
...
The build applies the required version:
$ echo New version= ${MAVEN_VERSION}
New version= -Drevision=3.0.7-SNAPSHOT
$ mvn $MAVEN_CLI_OPTS ${MAVEN_VERSION} deploy -DskipTests

The pom file to be installed can be explicitly set:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<configuration>
<pomFile>.flattened-pom.xml</pomFile>
</configuration>
</plugin>
Above, flatten-maven-plugin has been previously invoked to produce .flattened-pom.xml

If you do a test by adding -Drevision=<someVersion> to the command line, does that produce correct results in Nexus?
I suspect it will.
Properties are interpolated very early in the process. When the command first runs, ${revision} is undefined, so Maven leaves it as-is. The flatten then calculates ${revision}, but that only applies from the time the plugin runs and later.
You can try researching "late binding" properties (they start with '#' instead of '$') but I'm not sure if those work in top level fields like the GAV coords.

Related

Duplication in maven: are profiles additive to project, or do they replace declared items?

Provided you have the following defined in your POM.xml:
<project>
<!-- ... -->
<build>
<plugins>
<plugin>
<artifactId>plugin-X</artifactId>
<!-- plugin config -->
</plugin>
<plugins>
</build>
<profiles>
<profile>
<id>foo</id>
<build>
<plugins>
<plugin>
<artifactId>plugin-X</artifactId>
<!-- plugin config -->
</plugin>
<plugins>
</build>
<profile>
</profiles>
</project>
If the plugin config for plugin-X is exactly the same for profile foo as it is for a build without a selected profile, do you have to redeclare the plugin at all on the profile level? If so, do you also have to redeclare all config settings for it?
If you declared plugin-Y in project.profile.build.plugins instead of plugin-X (but left it declared on the project level), which plugins would be run when you run mvn -P foo? Only plugin-Y, or also plugin-X?
More generally speaking, are profiles additive to what is declared on the project level, or do they override it? (If they are additive, how do you "remove" entities that were declared on a project level when you run a build profile and don't want them for that specific profile?)
I know profile configuration gets inherited from parent pom files ("from either the build/plugins or pluginManagement sections of the parent") with options "merge", "append", and "override". I think what I really want to know is: how does maven behave when the same/similar information is defined on the project and profile levels in the same pom file...
This isn't a full answer, but another piece of the puzzle - in addition to my earlier comments, and maven's Guide to Configuring Plug-ins.
Given the following pom.xml file:
</profiles>
<properties>
<foo>main</foo>
<bar>main</bar>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>validate</phase>
<configuration>
<target>
<echo>${foo}</echo>
<echo>${bar}</echo>
<echo>${baz}</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>p</id>
<properties>
<bar>prof</bar>
<baz>prof</baz>
</properties>
</profile>
</profiles>
</project>
When I run mvn validate, I get the following output:
[echo] main
[echo] main
[echo] ${baz}
Running mvn validate -P p however yields:
[echo] main
[echo] prof
[echo] prof
That means that properties at least are merged, appending new items and replacing those that are redefined.
Also, if I add another plugin to the profile (such as surefire), it will execute when running the profile with mvn <phase> -P p, so the profile inherits antrun and adds surefire. Plugin re-definitions however replace the original; adding
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>validate</phase>
<configuration>
<target>
<echo>Tada!</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
only prints Tada!, but no longer the original antrun output (even when changing the new addition's phase to initialize. Adding <inherited>true</inherited> to any of the two plugin definitions doesn't make a difference. The behaviour might be plugin-specific, though.

How to reference a properties file on Master and Child POM's

I have a master POM file that defines two profiles: QA and Production. It uses the properties-maven-plugin to set some vars that are later used by the wildfly-maven-plugin to deploy the packages to the web server.
Something like this:
[MASTER POM]
<profile>
<id>qa</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>../build-qa.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
And on the Child POMs:
<parent>
<groupId>fhng.apps</groupId>
<artifactId>fhng-build-all</artifactId>
<version>1.0</version>
</parent>
(...)
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.1.0.Alpha11</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<hostname>${wildfly.server}</hostname>
<port>${wildfly.port}</port>
<username>${wildfly.username}</username>
<password>${wildfly.password}</password>
<filename>myapp.war</filename>
</configuration>
</plugin>
the Master POM is located on the project root and each particular web application is located on a sub-folder. This works if I run mvn install from each particular project folder. I would very much like to run "mvn -Pqa clean install" from the master pom folder. However it fails because the master pom references ..\build-qa.properties which works from each project but obviously is invalid from the parent directory.
Is where a way to solve this? Is it possible to reference a file relative to the Master POM folder, irrespective of which particular POM is built? I understand that this approach breaks the maven premise that the parent package must not necessarily be present on our working dir.
As an alternative, is there a way to reference the properties files as an artifact of the parent package? So that maven is able to get said parent package from the repo and use a file inside it?
I would also accept a way to "skip" ou "disable" the initialize/compile/install phase on the parent pom so that it won't try to read the .properties files.
Thank you!
If in root folder you put directory .mvn/, you can refer to root folder by ${maven.multiModuleProjectDirectory}
I current case:
<file>${maven.multiModuleProjectDirectory}/build-qa.properties</file>
Ref: http://takari.io/2015/03/20/mmp.html
PS. Remember that empty folder is not comitted to git

How To Use The Sonar Maven Plug-in

Easy question here. I want to add sonar to be executed on every Maven build. I tried:
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.1.1</version>
</plugin>
and
<plugin>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>5.1</version>
</plugin>
and
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.7.1</version>
</plugin>
because a) I couldn't figure out what the plug-ins do and/or b) which one is the current one.
If I only add the above to <build> -> <plugins> it's not executed ever (so the plug-in doesn't have a default execution). So of course I added a <execution> instruction, and after that Sonar gets executed, but with the following error message:
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>sonar</goal>
</goals>
</execution>
</executions>
Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.1.1:sonar (default) on project org.acme.project.build: Can not execute Findbugs: This project contains Java source files that are not compiled.
It does not seem to matter which phase I use (I tried validate and compile and test and prepare-package and package even though not all of them make sense). I am sure there is no source code generation anywhere in the project. And the static classes get compiled just fine.
I think the problem might be that the plug-in gets executed for every module, including the parent pom project. Which is weird, because sonar:sonar skips that project.
But the project structure is simple and I can't find anything unusual about it:
<groupId>group</groupId>
<artifactId>org.acme.project.build</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>org.acme.project</module>
</modules>
<profiles>
<profile>
<id>sonar</id>
<properties>
<sonar.host.url>http://sonar.acme.org/</sonar.host.url>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>sonar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
The project org.acme.project has nothing besides its own artifact ID and the parent. The command line is: mvn clean deploy -Dsonar.login=Wile.Coyote -Dsonar.password=*********** -Psonar
The log shows that sonar is always executed before the install phase, which of course is way to early.
So how do I use Sonar's Maven plug-in to analyze my code?
a) I couldn't figure out what the plug-ins do
The plugin is used to gather the details from code coverage reports and the repository code scanning for getting to analyze possible bugs, duplications etc. You can search for a sample sonar report to find what all and how to get these details with maven using two methods like settings.xml and maven plugin is detailed at SonarQube Scanner for Maven and
SonarQube - analyzing with Maven
b) which one is the current one.
The maven central suggests that the current plugin from org.codehaus.mojo used as
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.2</version>
</plugin>
has been moved to
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.2</version>
</plugin>
So you should ideally be using the one from groupId - org.sonarsource.scanner.maven as also suggested by the SonarQube Docs
Also the artifact from org.codehaus.sonar version 5.1 seems to be outdated and not maintained.

Aggregate findbugs report in Maven 3.0.5

I am using multi-module Maven Project ( more than 10 modules ). I am trying to create a findbugs report of all module in single html page. Is there any way?
For creating individual report for each module, i am using the below
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<!--
Enables analysis which takes more memory but finds more bugs.
If you run out of memory, changes the value of the effort element
to 'Low'.
-->
<effort>Max</effort>
<!-- Build doesn't fail if problems are found -->
<failOnError>false</failOnError>
<!-- Reports all bugs (other values are medium and max) -->
<threshold>Low</threshold>
<!-- Produces XML report -->
<xmlOutput>false</xmlOutput>
<skip>${skipFindbugs}</skip>
<!-- Configures the directory in which the XML report is created -->
<findbugsXmlOutputDirectory>${project.build.directory}/findbugs</findbugsXmlOutputDirectory>
</configuration>
<executions>
<!--
Ensures that FindBugs inspects source code when project is compiled.
-->
<execution>
<phase>compile</phase>
<goals>
<goal>findbugs</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<transformationSets>
<transformationSet>
<!-- Configures the source directory of XML files. -->
<dir>${project.build.directory}/findbugs</dir>
<!-- Configures the directory in which the FindBugs report is written.-->
<outputDir>${project.build.directory}/findbugs</outputDir>
<!-- Selects the used stylesheet. -->
<!-- <stylesheet>fancy-hist.xsl</stylesheet> -->
<stylesheet>${project.parent.basedir}/default.xsl</stylesheet>
<!--<stylesheet>plain.xsl</stylesheet>-->
<!--<stylesheet>fancy.xsl</stylesheet>-->
<!--<stylesheet>summary.xsl</stylesheet>-->
<fileMappers>
<!-- Configures the file extension of the output files. -->
<fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
<targetExtension>.html</targetExtension>
</fileMapper>
</fileMappers>
</transformationSet>
</transformationSets>
</configuration>
<executions>
<!-- Ensures that the XSLT transformation is run when the project is compiled. -->
<execution>
<phase>compile</phase>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>findbugs</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
</plugin>
According to official documentation of the plugin (question n. 1), it is not possible.
However, here is the approach I used to achieve it:
Add an additional module to your existing multimodule project. This additional module will only be used for reporting
Configure the Buildhelper Maven Plugin to dynamically add the source code of the other modules to the reporting module. Note: you can do the same for resources, if required.
Configure the Findbugs plugin only on the reporting module
Add the other modules as dependencies of the reporting module, in order to have the Maven reactor build to build it only at the end.
If required: you don't want the reporting module to be part of your default build, create a profile in the aggregator/parent module which redefines the modules element and add the reporting module to it. As such, only when the profile will be activated (i.e. via command line, on demand) the reporting module will be added and the aggregated report will be created.
As an example, in the aggregator/parent module you can define as following:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample</groupId>
<artifactId>findbugs-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>findbugs-module1</module>
<module>findbugs-module2</module>
</modules>
<profiles>
<profile>
<id>findbugs-reporting</id>
<modules>
<module>findbugs-module1</module>
<module>findbugs-module2</module>
<module>findbugs-reporting</module>
</modules>
</profile>
</profiles>
</project>
Note: the findbugs-reporting module is only added in the findbugs-reporting profile. By default, the build will ignore it.
In the findbugs-reporting module, configure the POM using the configuration you posted (findbugs and XML maven plugin) and also add as following:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>..\findbugs-module1\src\main\java</source>
<source>..\findbugs-module2\src\main\java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Note the added sources from other modules (change it according to your project).
Furthermore, we also need to add dependencies to the reporting module. It has to depend on other modules in order to be built at the end (and as such make sure to take the latest changes/sources from other modules). As an example:
<dependencies>
<dependency>
<groupId>com.sample</groupId>
<artifactId>findbugs-module1</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.sample</groupId>
<artifactId>findbugs-module2</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
Finally, you can invoke the reporting build as following from the aggregator/parent dir:
mvn clean install -Pfindbugs-reporting
As such, you will build the whole project and additionally activate the reporting module, which will dynamically include sources from other modules (as configured) and generate an aggregated report.
Depending on your needs, you can avoid the profile step (if you want it as part of your default build) or activate the profile by default (so that you can skip the reporting build deactivate it via -P!findbugs-reporting) or use the skipFindbugs property you already configured (and without the profile, in such a case).

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

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 to execute goal org.apache.maven.plugins:maven-install-plugin:2.3.1:install (default-cli) on project StarTeamCollisionUtil: The packaging for this project did not assign a file to the build artifact -> [Help 1]
What does this mean and how can I fix it? Below is my pom.xml. Let me know what other info would be helpful and I'll edit this post. Thanks, - Dave
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myco.starteam.util</groupId>
<artifactId>StarTeamCollisionUtil</artifactId>
<packaging>jar</packaging>
<name>StarTeam Collision Util</name>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>myco-sonatype-nexus-snapshots</id>
<name>MyCo Sonatype-Nexus Snapshots</name>
<url>http://sonatype.myco.com/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8.1</version>
</plugin>
</plugins>
</build>
</project>
I don't know if this is the answer or not but it might lead you in the right direction...
(I believe these steps are for people working with Intellij IDE. The install:install is available in the Maven panel on the right by default. The below steps are alternative to it.)
The command install:install is actually a goal on the maven-install-plugin. This is different than the install maven lifecycle phase.
Maven lifecycle phases are steps in a build which certain plugins can bind themselves to. Many different goals from different plugins may execute when you invoke a single lifecycle phase.
What this boils down to is the command...
mvn clean install
is different from...
mvn clean install:install
The former will run all goals in every cycle leading up to and including the install (like compile, package, test, etc.). The latter will not even compile or package your code, it will just run that one goal. This kinda makes sense, looking at the exception; it talks about:
StarTeamCollisionUtil: The packaging for this project did not assign a file to the build artifact
Try the former and your error might just go away!
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.
This reply is on a very old question to help others facing this issue.
I face this failed error while I were working on my Java project using IntelliJ IDEA IDE.
Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install (default-cli) on project getpassword: The packaging for this project did not assign a file to the build artifact
this failed happens, when I choose install:install under Plugins - install, as pointed with red arrow in below image.
Once I run the selected install under Lifecycle as illustrated above, the issue gone, and my maven install compile build successfully.
I have same issue.
Error message for me is not complete. But in my case, I've added generation jar with sources. By placing this code in pom.xml:
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
So in deploy phase I execute source:jar goal which produces jar with sources. And deploy ends with BUILD SUCCESS
This error shows up when using the maven-install-plugin version 3.0.0-M1 (or similar)
As already mentioned above and also here the following plug-in version works:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
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
While #A_Di-Matteo answer does work for non multimodule I have a solution for multimodules.
The solution is to override every plugin configuration so that it binds to the phase of none with the exception of the jar/war/ear plugin and of course the deploy plugin. Even if you do have a single module my rudimentary tests show this to be a little faster (for reasons I don't know) performance wise.
Thus the trick is to make a profile that does the above that is activated when you only want to deploy.
Below is an example from one of my projects which uses the shade plugin and thus I had to re-override the jar plugin not to overwrite:
<profile>
<id>deploy</id>
<activation>
<property>
<name>buildStep</name>
<value>deploy</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>test-compile</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>default-test</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>default-install</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>default-resources</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testResources</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>default</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<configuration>
<forceCreation>false</forceCreation>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Now if I run mvn deploy -Pdeploy it will only run the jar and deploy plugins.
How you can figure out which plugins you need to override is to run deploy and look at the log to see which plugins are running. Make sure to keep track of the id of the plugin configuration which is parens after the name of the plugin.
I had the same issue but I executed mvn install initially (not install:install as it was mentioned earlier).
The solution is to include:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
Into plugin management section.
This worked for me when I got the same error message...
mvn install deploy
I have seen this error occur when the plugins that are needed are not specifically mentioned in the pom. So
mvn clean install
will give the exception if this is not added:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
Likewise,
mvn clean install deploy
will fail on the same exception if something like this is not added:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
It makes sense, but a clearer error message would be welcome
You are missing properties tag:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
A working version of pom.xml file should look like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>se-lab1</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
org.hkr.Main
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>
</project>
I hope this helps someone but I accidentally added a module to my project and it changed my pom file from
<packaging>jar</packaging>
to
<packaging>pom</packaging>
so I just changed it back to
<packaging>jar</packaging>
and it worked to create the jar again
I have encountered a similar issue:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:3.0.1:install (default-install) on project MyProject: The packaging for this project did not assign a file to the build artifact -> [Help 1]
In my case, the error was due to blank spaces in my project directory path e.g.:
~\Documents\Job\My Project\my-project
I have renamed the directory in order to have a project path without blank spaces and it worked fine.

Resources