Exclude log4j.properties in the generated jar - maven

I am using maven-compiler-plugin to build a JAR from one of my module, and I am not able to exclude log4j.properties from the generated JAR.
I tried:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>8</source>
<target>8</target>
<excludes>
<exclude>**/log4j.properties</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
But this does not work. I can exclude the file globally:
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>log4j.properties</exclude>
</excludes>
</resource>
</resources>
But I don't want to do this as this impact the Eclipse build, and makes it impossible to run code from Eclipse that uses log4j.
I tried to see if the included log4j.properties was mine and not from another module, and it is mine. I've read numerous posts on the issue, including some here, but I still cannot solve it...
If this matters, this module is a submodule of a parent package, with the following <build>:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
</configuration>
<executions>
<execution>
<id>create-javadoc</id>
<phase>javadoc</phase>
<goals>
<goal>javadoc</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
</build>

Related

Preparing Tests for upload into Appcenter does not include src classfiles

I hope someone can help. When I am trying to prepare my tests to upload into appcenter for mobile testing, the command they tell me to use to prepare the upload does not include the src class files for my tests. It only adds the test class files that are specified in the "prepare-for-upload" section in the pom file.
when I upload and run the tests, it complains that it can not find the class files in classes.
I think that is because it isn't in the upload folder.
All the things I have tried still only leaves me with the following folders and files
This is all new to me so I have read so much without success.
I have tried to add the resources to the pom.xml and it still does not package them correctly.
I added this section to the pom file in the same tag as the Appcenter stuff.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<useSystemClassLoader>true</useSystemClassLoader>
</configuration>
</plugin>
I tried the following as well to see if I can copy the resources over.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-classes</id>
<phase>package</phase>
<goals>
<goal>resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/upload/classes</outputDirectory>
<resources>
<resource>
<directory>
${project.build.directory}/classes
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
This is my section that is meant for appcenter:
<profiles>
<profile>
<id>prepare-for-upload</id>
<build>
<plugins>
<!-- Owen Added-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-classes</id>
<phase>package</phase>
<goals>
<goal>resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/upload/classes</outputDirectory>
<resources>
<resource>
<directory>
/Users/owensieber/Projects/mobileautomation/target/classes
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/upload/dependency-jars/</outputDirectory>
<useRepositoryLayout>true</useRepositoryLayout>
<copyPom>true</copyPom>
<addParentPoms>true</addParentPoms>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>generate-pom</id>
<phase>package</phase>
<goals>
<goal>effective-pom</goal>
</goals>
<configuration>
<output>${project.build.directory}/upload/pom.xml</output>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-testclasses</id>
<phase>package</phase>
<goals>
<goal>testResources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/upload/test-classes</outputDirectory>
<resources>
<resource>
<directory>
${project.build.testOutputDirectory}
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

"no main manifest attribute" while running Jar after building with maven

I have a problem getting a maven build to work properly. It builds just fine, except the Main-Class within the manifest file found in the JAR is not present.
Currently, I have one parrent POM, and one POM for each of two modules. The reactor summary shows a success on all three buils.
However, when I try to run the jar in one of the modules, I am told "no main manifest attribute" exists. Checking the content of the manifest-file within the jar shows the Main-Class is not set:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: user
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_66
This is the build content of the parrent POM:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<executable>${java.compiler}</executable>
<verbose>${java.compiler.verbose}</verbose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<configuration>
<quiet>${javadoc.quiet}</quiet>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>package</phase>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<modules>
<module>ConsolidatedCustomerMasterEndpoint</module>
<module>ConsolidatedCustomerMasterService</module>
</modules>
And this is the build content of the module POM:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<mainClass>no.xyz.ccm.config.CcmApp</mainClass>
<classifier>jetty</classifier>
<requiresUnpack>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>CcmService</artifactId>
</dependency>
</requiresUnpack>
<addResources>false</addResources>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${maven-build-helper-plugin.version}</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/generated/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
<configuration>
<delimiters>
<delimiter>#</delimiter>
</delimiters>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

Maven, automating the version change

Let's say I have a pom file,
<version>14.4.1-SNAPSHOT</version>
which defines a version of the project to build. This value is updated automatically by our build system (jenkins).
Later on, in one of the plugins, I need to have a property, which incorporates the first two figures from the version, so that for 14.4.1-SNAPSHOT value, it would be "14.4", and for 13.12.39-SNAPSHOT value it would be "13.12".
Currently we update this value manually each month:
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>2.0.1</version>
<executions>
<execution>
<id>default-cli</id>
<phase>process-resources</phase>
<configuration>
<changeLogFile>src/main/resources/14.4/changeLog.xml</changeLogFile>
Ideally, I would love to have instead something like
<changeLogFile>src/main/resources/${releaseVersion}/changeLog.xml</changeLogFile>
But how would I get this ${releaseVersion} (=14.4) calculated automatically from the <version>14.4.1-SNAPSHOT</version> ?
In that case it is absolutely automated, and we do not have any manual process in place.
Is there any expressions-kind-of-language I can use in pom files, which could parse the string 14.4.1-SNAPSHOT and produce from it an 14.4 ?
You can try the mojo build-helper with parse-version for this.
Stack Overflow Question
Original Documentation
[Edit] Here's my example pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<webResources>
<resource>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
<directory>src/main/resources/${parsedVersion.majorVersion}.${parsedVersion.minorVersion}</directory>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>validate</phase>
<id>parse-version</id>
<goals>
<goal>parse-version</goal>
</goals>
<configuration>
<propertyPrefix>parsedVersion</propertyPrefix>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Major: ${parsedVersion.majorVersion}</echo>
<echo>Minor: ${parsedVersion.minorVersion}</echo>
<echo>Incremental: ${parsedVersion.incrementalVersion}</echo>
<echo>Qualifier: ${parsedVersion.qualifier}</echo>
<echo>BuildNumber: ${parsedVersion.buildNumber}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

yuicompressor maven plugin and maven-war-plugin

I've been struggling with getting this plugin to play nicely with the maven-war-plugin for a couple of hours now and I thought it was time to ask for help. I have the plugin defined as follows:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<id>compressyui</id>
<phase>process-resources</phase>
<goals>
<goal>compress</goal>
</goals>
<configuration>
<nosuffix>true</nosuffix>
<warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
<jswarn>false</jswarn>
</configuration>
</execution>
</executions>
</plugin>
If I remove nosuffix=true then I can see the compressed/minified -min.js files get into the war as expected, but with this flag on they are being overwritten by the maven-war-plugin (I'm assuming) when it builds the war file. I really need the file names to remain the same though ... does anyone have an idea of what I need to change in order to use the same filenames and still get the minified versions into the final war?
OK. I finally figured this out. You need to define a <webappDirectory> in the yuicompressor plugin that can then be referenced as a <resource> in the maven-war-plugin. In the example below I'm using <directory>${project.build.directory}/min</directory>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<id>compressyui</id>
<phase>process-resources</phase>
<goals>
<goal>compress</goal>
</goals>
<configuration>
<nosuffix>true</nosuffix>
<warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
<webappDirectory>${project.build.directory}/min</webappDirectory>
<jswarn>false</jswarn>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<executions>
<execution>
<id>default-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
<encoding>UTF-8</encoding>
</configuration>
</execution>
</executions>
<configuration>
<warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
<encoding>UTF-8</encoding>
<webResources>
<resource>
<directory>${project.build.directory}/min</directory>
</resource>
</webResources>
</configuration>
</plugin>
Just configure 'warSourceExcludes' on the WAR plugin.
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceExcludes>**/*.css,**/*.js</warSourceExcludes>
</configuration>
</plugin>
I would like to add the configuration which worked for me:
First, to fix m2e complaining about the 'Plugin execution not covered by lifecycle' I added the following in the parent pom taken from this post:
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse
m2e settings only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>compress</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Then in the war pom I put:
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
<configuration>
<linebreakpos>300</linebreakpos>
<excludes>
<exclude>**/*-min.js</exclude>
<exclude>**/*.min.js</exclude>
<exclude>**/*-min.css</exclude>
<exclude>**/*.min.css</exclude>
</excludes>
<nosuffix>true</nosuffix>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceExcludes>**/*.css,**/*.js</warSourceExcludes>
</configuration>
</plugin>
</plugins>
</build>
This generates the minified css and js files in the project build target directory while excluding the original files.
I hope this saves someone time.
this is my configuration, and it works fine in my maven web project:
<!-- js/css compress -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<excludes>
<exclude>**/*-min.js</exclude>
<exclude>**/*.min.js</exclude>
<exclude>**/*-min.css</exclude>
<exclude>**/*.min.css</exclude>
</excludes>
<jswarn>false</jswarn>
<nosuffix>true</nosuffix>
</configuration>
<executions>
<execution>
<id>compress_js_css</id>
<phase>process-resources</phase>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- war -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/${project.build.finalName}/resources</directory>
<targetPath>/resources</targetPath>
<filtering>false</filtering>
</resource>
</webResources>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
The approach I use is a bit different.
First, I've configured my IDE to run mvn process-resources before the compilation/packaging. This way the files are created before the war is assembled.
It is very important to set <nosuffix>false</nosuffix> and <outputDirectory>${basedir}/src/main/resources/</outputDirectory> so the files can be created in the same directory without replacing your original source files.
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<preProcessAggregates>false</preProcessAggregates>
<excludes>
<exclude>**/*-min.js</exclude>
<exclude>**/*.min.js</exclude>
<exclude>**/*-min.css</exclude>
<exclude>**/*.min.css</exclude>
</excludes>
<jswarn>false</jswarn>
<nosuffix>false</nosuffix> <!-- VERY IMPORTANT WILL REPLACE YOUR FILES IF YOU SET nosuffix TO TRUE OR DONT SET IT AT ALL -->
<outputDirectory>${basedir}/src/main/resources/</outputDirectory> <!-- by default the plugin will copy the minimized version to target directory -->
<failOnWarning>false</failOnWarning>
</configuration>
<executions>
<execution>
<id>compress_js_css</id>
<phase>process-resources</phase>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
</plugin>
As Jakob Kruse say, you must deal with the *.js, but no *.min.js, so my configurations is below, please notice the use of %regex[] :
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<id>compressyui</id>
<phase>process-resources</phase>
<goals>
<goal>compress</goal>
</goals>
<configuration>
<nosuffix>true</nosuffix>
<warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
<webappDirectory>${project.build.directory}/min</webappDirectory>
<jswarn>false</jswarn>
<excludes>
<exclude>**/*-min.js</exclude>
<exclude>**/*.min.js</exclude>
<exclude>**/*-min.css</exclude>
<exclude>**/*.min.css</exclude>
<exclude>**/jquery.window.js</exclude>
......
<exclude>**/compile.js</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<packagingExcludes>servlet-api*.jar,target/test-classes/*</packagingExcludes>
<warSourceExcludes>test/**,%regex[.*(!min).js],%regex[.*(!min).css]</warSourceExcludes>
<webResources>
<resource>
<directory>${project.build.directory}/min</directory>
</resource>
</webResources>
</configuration>
</plugin>
Without pom.xml change
mvn net.alchim31.maven:yuicompressor-maven-plugin:compress
To force compress every js and css files and fail if warning
mvn net.alchim31.maven:yuicompressor-maven-plugin:compress \
-Dmaven.yuicompressor.force=true \
-Dmaven.yuicompressor.failOnWarning=true \
For more options:
http://davidb.github.io/yuicompressor-maven-plugin/usage_compress.html

How to place the output jar into another folder with maven?

I'd like to place my output jar and jar-with-dependencies into another folder (not in target/ but in ../libs/).
How can I do that?
You can use the outputDirectory parameter of the maven-jar-plugin for this purpose:
<project>
...
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>../libs</outputDirectory>
</configuration>
</plugin>
...
</plugins>
</build>
...
</project>
But as cdegroot wrote, you should probably better not fight the maven way.
If you want to copy the artifact into a directory outside your project, solutions might be:
maven-jar-plugin and configure outputDirectory
maven-antrun-plugin and copy task
copy-maven-plugin by Evgeny Goldin
Example for the copy-maven-plugin is:
<plugin>
<groupId>com.github.goldin</groupId>
<artifactId>copy-maven-plugin</artifactId>
<version>0.2.5</version>
<executions>
<execution>
<id>deploy-to-local-directory</id>
<phase>install</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<skipIdentical>false</skipIdentical>
<failIfNotFound>false</failIfNotFound>
<resources>
<resource>
<description>Copy artifact to another directory</description>
<targetPath>/your/local/path</targetPath>
<directory>${project.build.directory}</directory>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Another way would be maven-resources-plugin (find the current version here):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-files-on-build</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/[TO-DIR]</outputDirectory>
<resources>
<resource>
<directory>[FROM-DIR]</directory>
<!--<include>*.[MIME-TYPE]</include>-->
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
I would do it this way:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>install</phase>
<configuration>
<target>
<copy file="target/${project.artifactId}-exec.jar" tofile="../../docker/${project.artifactId}.jar"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
This technique worked well for me:
http://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-artifacts.html
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
<destFileName>optional-new-name.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/wars</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
I specially like the solution using maven-resources-plugin (see here) because is already included in maven, so no extra download is needed, and also is very configurable to do the copy at a specific phase of your project (see here to learn & understand about phases). And the best part of this approach is that it won't mess up any previous processes or build you had before :)
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>/dir/where/you/want/to/put/jar</outputDirectory>
<resources>
<resource>
<directory>/dir/where/you/have/the/jar</directory>
<filtering>false</filtering>
<includes>
<include>file-you-want-to.jar</include>
<include>another-file-you-want-to.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
...
</project>
Of course you can also use interpolated variables like ${baseDir} and other good stuff like that all over your XML. And you could use wild cards as they explain here
Maven dependency plugin is perfectly capable of copying all dependencies and just built artifact in a custom location. Following example will copy all runtime dependencies and a built artifact in a two execution phases.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}/jars</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
<execution>
<id>copy-artifact</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>${project.packaging}</type>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/jars</outputDirectory>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
While documentation of dependency plugin states in its documentation that in order to copy built artifact you have to use any phase after the package phase, that is not true if you are building jars. In that situation you can use package phase. At least in 3.3.0 version of plugin.

Resources