How to ignore maven-dependency-plugin copy goal errors? - maven

I am copying a resource into another folder before packaging using the maven-dependecy-plugins copy goal.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<failBuild>false</failBuild>
<artifactItems>
<artifactItem>
<groupId>my.groupID</groupId>
<artifactId>myArtifact</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>my/custom/path</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
The resource is not vital and it is likely possible that it is not accessible. That's why I want the build not to fail if it is not accessible. I already set the failBuild property to false but it had no effect. Is there a way to achieve this?

I guess you get a resolve problem, that the artifact doesnt exist or can't be found in any repository. That's how maven works, if you specify a dependency you need to be able to retrieve it.

I resolved my problem by using the copy artifact plugin of jenkins now.

Related

how does copy-resources work

I tried using maven-resources-plugin with goal copy resources.It copied all the resources to the output directory.I needed only a single jar.How to make it possible?
My requirement was to add a maven dependency to resources folder so atht I can add it to my Kie-Container and execute the rules residing inside the jar.I achieved it using maven-dependency-plugin with goal "copy".The mistake I did was not specifying the artifactItem.Afte I used artifactItem and included my jar description it worked.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>SampleDroolsWBTest</groupId>
<artifactId>DroolsAPI</artifactId>
<version>2.0</version>
<overWrite>false</overWrite>
<outputDirectory>${basedir}/src</outputDirectory>
<includes>pom.xml</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>

Download war file from nexus with maven

If I have the artifactId, the groupId and the version how I can configure the pom.xml so maven will download test.war file from the nexus repository.
I assume that this should happened in the
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
.....
</plugin>
In the execution block.
I already tried this but no luck:
<execution>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<artifactId>mytest</artifactId>
<groupId>com.mytest</groupId>
<version>${version}</version>
<type>war</type>
<destFileName>mytest-${version}.war</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
Are you certain that ${version} is being set properly for you? If you need the version of the current project, you should probably be using <version>${project.version}</version> and possibly setting up <dependencyManagement/> to handle that for you.

Maven extract Dependency without creating dependency directory

The configuration below works but I end up with an extra directory that I don't want. So I have target/webapp/dep-A/<depedency contents>, what do i need to change to get it to be target/webapp/<depedency contents>?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>myGroup</groupId>
<artifactId>dep-A</artifactId>
<version>1.0-SNAPSHOT</version>
<type>zip</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/webapp</outputDirectory>
</artifactItem>
</artifactItems>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
Unfortunately the maven-dependency-plugin unpack goal has not a postprocess optional parameter letting you, for example, chmod-ing or moving files. So I don't think exists an elegant way to do what you want only using the maven-dependency-plugin.
In addition to the maven-dependency-plugin you might use the maven-antrun-plugin, binding it to a subsequent phase which the maven-dependency-plugin is binded to, to copy/move/delete your files and directories.

How to add resources of an external jar into my maven build jar?

I have a module , while building this module i want to include some resources from an external jar into my module jar.
I tried to use maven-shade-plugin but I am not able to achieve it it.
Any help is appreciated.
Unpack your external resource into project target, after this unpacked resources will be included in generated artifact.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>process-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.0</version>
<type>jar</type>
<includes>*.xsb, *.properties</includes>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
For non-maven file use method from this answer https://stackoverflow.com/a/3264160/516167

How to use artifactId with different filename in dependencies

Using Artifactory and Maven, how can one refer to a dependency with the correct group/artifactId/version but use a filname that differs from the artifactId-version.end style?
The problem comes with a dll that cannot be renamed, and the mandatory? Artifactory naming convention.
edit
found one possible expensive way for this specific problem where the filename cannot include the dash-sign: creating a new Artifactory repository layout for which the pro-version is needed - so unfortunately, that is not an option!
partly solution for jUnit tests
using the maven-dependency-plugin and the maven-surefire-plugins one can make jUnits work. unfortunately, it does not solve the problem that the specific sapjco3.dll cannot be found when deployed within a war to a server.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>copy</id>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>sapjco</groupId>
<artifactId>sapjco3</artifactId>
<version>3.0.7</version>
<type>dll</type>
<classifier>win32</classifier>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</artifactItem>
</artifactItems>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<property>
<name>java.library.path</name>
<value>${project.build.directory}/lib</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
Maven does not care for filenames, it cares for their coordinates. Add your DLL correctly to your remote repo and maven will do the rest.
A dependency snippet might be:
<dependency>
<groupId>com.company</groupId>
<artifactId>my.artifact</atifactId>
<version>1.0</version>
<type>dll</type>
<classifier>win32</classifier>
</dependency>
After you have done this, use either dependency:copy-dependencies or dependency:copy to change the filename at build time.

Resources