Maven 3 - Distribute custom plugin in a .jar? - maven

Complete Maven newb here, so forgive any abused terminology, etc.
I've built a custom plugin in Maven 3 (one that defines goals for git rebase). I'm able to:
mvn install
No problem. I can then invoke the goal from the command line:
mvn edu.clemson.cs.rsrg:git-plugin:rebase
Everything's golden. I have this lovely git-plugin-XXX.jar file sitting in my target directory.
I'd like to make my custom goals available to another project such that when other members of the dev team pull down that project's source, they get my plugin for free (or at least, after a mvn build).
My understanding is that the purist solution is to set up a maven repo for the group and load my plugin there, but that seems overkill for a single hacky plugin.
Thoughts?
I've played with doing it via three different plugins so far:
addjars-maven-plugin:add-jars
<plugin>
<groupId>com.googlecode.addjars-maven-plugin</groupId>
<artifactId>addjars-maven-plugin</artifactId>
<version>1.0.4</version>
<executions>
<execution>
<goals>
<goal>add-jars</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${basedir}/plugins</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Gives me this error during mvn build:
[ERROR] Error resolving version for plugin 'edu.clemson.cs.rsrg:git-plugin' from the repositories [local (/home/hamptos/.m2/repository), central (http://repo.maven.apache.org/maven2)]: Plugin not found in any plugin repository
It also causes my later formatting plugin to fail. (Clearly it's read the jar and determined the group name/plugin name, but then it goes and looks for it in my local repo? Of course it's not there--I'm trying to install it.)
build-helper:attach-artifacts
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>install</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${basedir}/plugins/git-plugin-0.1.0a.jar</file>
<type>jar</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
Gives me this error during mvn build:
[ERROR] Failed to execute goal org.codehaus.mojo:build-helper-maven-plugin:1.7:attach-artifact (attach-artifacts) on project RESOLVE: Execution attach-artifacts of goal org.codehaus.mojo:build-helper-maven-plugin:1.7:attach-artifact failed: For artifact {edu.clemson.cs.rsrg:RESOLVE:12.09.01a:jar}: An attached artifact must have a different ID than its corresponding main artifact.
(RESOLVE:12.09.01a being the main project. Clearly something's gone awry here because the plugin and main project definitely have different artifactIDs. Trying to attach the project on top of itself maybe?)
maven-install-plugin:install-file
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>install-git-plugin</id>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${basedir}/plugins/git-plugin-0.1.0a.jar</file>
<packaging>jar</packaging>
<groupId>edu.clemson.cs.rsrg</groupId>
<artifactId>git-plugin</artifactId>
<version>0.1.0a</version>
</configuration>
</execution>
</executions>
</plugin>
Seems to work fine until I try to invoke one of the goals like mvn edu.clemson.cs.rsrg:git-plugin:rebase, at which point it gives me this error:
[ERROR] Failed to execute goal edu.clemson.cs.rsrg:git-plugin:0.1.0a:rebase (default-cli) on project RESOLVE: Execution default-cli of goal edu.clemson.cs.rsrg:git-plugin:0.1.0a:rebase failed: Unable to load the mojo 'rebase' (or one of its required components) from the plugin 'edu.clemson.cs.rsrg:git-plugin:0.1.0a': com.google.inject.ProvisionException: Guice provision errors:
[ERROR]
[ERROR] 1) Error in ComponentFactory:ant-mojo
[ERROR] at ClassRealm[plugin>edu.clemson.cs.rsrg:git-plugin:0.1.0a, parent: sun.misc.Launcher$AppClassLoader#e776f7]
[ERROR] while locating org.apache.maven.plugin.Mojo annotated with #com.google.inject.name.Named(value=edu.clemson.cs.rsrg:git-plugin:0.1.0a:rebase)

You may think it is hacky, but it is the maven way. It needs to be deployed to a maven repo.
If you keep it in a groupId that you can demonstrably own and it's open source you can publish it to central

Related

Maven-cannot release due to local modicfications

We have been releasing our project via Jenkins pipeline. We have a shared pipeline and the mvn release command executes with options
"'-Dgoals=deploy -DpushChanges=false -DlocalCheckout=true -DpreparationGoals=initialize ' +
'-Darguments="-Dmaven.javadoc.skip=true -Dskip.master=true" -DtagNameFormat="#{project.version}" ' +
'-Dresume=false'".
With one of recent project during maven release phase , it fails stating " Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:prepare (default-cli) on project myProject: Cannot prepare the release because you have local modifications :
14:00:25 [main] ERROR org.apache.maven.cli.MavenCli - [myProject/src/main/java/com/schema/avro/GlobalLinePlanStyle.java:modified].
This file is an autogenerated file for avro schema, which is generated by adding the below plugin in pom.xml
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>${avro.version}</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/resources/</sourceDirectory>
<outputDirectory>${project.basedir}/src/main/java/</outputDirectory>
<fieldVisibility>PRIVATE</fieldVisibility>
<includes>
<include>**/*.avsc</include>
</includes>
<testIncludes>
<testInclude>**/*.test</testInclude>
</testIncludes>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
</execution>
</executions>
</plugin>
I have tried adding the explicit maven release plugin in pom.xml as below but that also have not solved the issue
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<checkModificationExcludes>
<checkModificationExclude>com/schema/avro/GlobalLinePlanStyle.java</checkModificationExclude>
</checkModificationExcludes>
</configuration>
</plugin>
Since release:prepare expects to find "filters" in checkModificationExcludes configuration setting:
A list of additional exclude filters that will be skipped when checking for modifications on the working copy. Is ignored, when checkModificationExcludes is set.
you need to specify either path relative to project root, i.e.:
<checkModificationExcludes>
<checkModificationExclude>src/main/java/com/schema/avro/GlobalLinePlanStyle.java</checkModificationExclude>
</checkModificationExcludes>
or ant pattern:
<checkModificationExcludes>
<checkModificationExclude>**/com/schema/avro/GlobalLinePlanStyle.java</checkModificationExclude>
</checkModificationExcludes>
BTW, I do not like such setup, because in my opinion generated source files must not reside in the project structure at all, however other developers report they experience other difficulties with proper setup of avro-maven-plugin.

maven-dependency-plugin analyze - "Skipping project with no build directory"

I'm running mvn dependency:analyze-only & im getting the error below. Can someone point me to the correct config for running the maven dependency analyzer?.
FYI, my project builds fine with maven, so im not sure what its looking for. I also listed my pom.xml for the plugin.
this is the error im getting
[INFO]
[INFO] --- maven-dependency-plugin:2.10:analyze-only (default-cli) # MFC ---
[INFO] Skipping project with no build directory
...
This is my pom.xml for the dependency plugin
...
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>analyze</id>
<goals>
<goal>analyze</goal>
</goals>
<configuration>
<failOnWarning>true</failOnWarning>
<outputDirectory>c:\TEMP\</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Note that the dependency:analyze-only goal is used in preference to dependency:analyze since it doesn't force a further compilation of the project, but uses the compiled classes produced from the earlier test-compile phase in the lifecycle.
The project's dependencies will then be automatically analyzed during the verify lifecycle phase
If you have not compiled or run your tests before, you will get that message.
Then you must execute as follows
>mvn verify dependency:analyze-only
or simply
> mvn verify
UPDATE
Your pluging goal must be <goal>analyze-only</goal> not <goal>analyze</goal> plugin then must be
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>analyze</id>
<goals>
<goal>analyze-only</goal>
</goals>
<configuration>
<failOnWarning>true</failOnWarning>
<outputDirectory>c:\TEMP\</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
do the change and execute mvn verify dependency:analyze-only or verify and it should works.

Can maven sortpom plugin affect a project's build result?

Can the Maven Sortpom Plugin affect the result of a project's build ?
Is it possible to have a project build fail just because the sortpom plugin was added ?
Normally the order of the elements in a pom.xml file does not matter, so reordering elements should not affect the build.
But I know of two exceptions to this rule:
Maven reads dependencies according to the order in the pom-file when compiling. Rearranging that order may affect the compilation output.
If two plugins executes in the same phase, the order in pom-file will determine which plugin to execute first. Sorting the plugins may cause the compilation to fail if the result of one plugin is dependent on another.
The sortpom plugin does not sort either dependencies nor plugins by default. So I would say that the sortpom plugin should not affect the result of a projects build.
It can fail a build:
[ERROR] Failed to execute goal com.google.code.sortpom:maven-sortpom-plugin:2.3.0:sort (default) on project data-extractor: scm.team.company.corp: Unknown host scm.team-project.company.corp -> [Help 1]
The if the file isn't found due to network problems, even when running with -o
Yes.
For example, you use:
org.codehaus.mojo:build-helper-maven-plugin's reserve-network-port goal in phase pre-integration-test
org.apache.tomcat.maven:tomcat7-maven-plugin's run goal also in phase pre-integration-test
Now, sortpom:sort orders them around, and in maven-3, the order of the plugins are important. So if you configure a random port for tomcat through the portName feature of reserve-network-port, the system property won't be filled (at the point it is needed), as after the sort, the build-helper artifact is executed AFTER the run goal is invoked.
Example after a sorting:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<!-- ... -->
</executions>
<configuration>
<fork>true</fork>
<port>${tomcat.http.port}</port><!-- Oops, not set (yet)! -->
</configuration>
</plugin>
<!-- ... -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper.version}</version>
<executions>
<execution>
<id>reserve-tomcat-port</id>
<phase>pre-integration-test</phase>
<goals>
<goal>reserve-network-port</goal>
</goals>
<configuration>
<portNames>
<portName>tomcat.http.port</portName><!-- Too late -->
</portNames>
</configuration>
</execution>
</executions>
</plugin>

maven plugin ignored from local pom plugins

I am new to maven, and cannot figure it out.
I have this configuration for the plugin in my pom.xml file, but it looks like mvn does not use my configuration.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<packaging>jar</packaging>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>
${project.build.directory}/${project.artifactId}-${project.version}.jar
</file>
</configuration>
</execution>
</executions>
</plugin>
I am getting the same error when I comment out this plugin. There are old discussions on the blogs that maven was ignoring configurations inside the execution. Is it still an issue ? How can I make maven to read my plugin declarations instead of something else? What does it run when my dependency is commented out?
Error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install- plugin:2.3.1:install-file (default-cli) on project core: The parameters 'file' for goal org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file are missing or invalid -> [Help 1]
From the error message and the information above, one possibility is that you are running mvn install:install-file on your project. Run mvn install instead.

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