Maven extract Dependency without creating dependency directory - maven

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.

Related

How to rename a file while unpacking an artifact with maven-dependency-plugin?

I'm using a maven-dependency-plugin to unpack a jar that contains several .sh scripts and that works as expected.
So I'm able to copy the files into the <outputDirectory>${project.build.dir}/main-scripts</outputDirectory>
But now I want to rename only one of them from run.sh to run-main.sh while unpacking. How could it be achieved with the dependency plugin?
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.main.libs</groupId>
<artifactId>main-scripts</artifactId>
<version>LATEST</version>
<type>jar</type>
<includes>*.sh</includes>
<outputDirectory>${project.build.dir}/main-scripts</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>

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.

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 ignore maven-dependency-plugin copy goal errors?

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.

Resources