maven-dependency-plugin:unpack Error - maven-3

I'm trying to extract some .exe files from a dependency jar file and put them under ${project.build.directory}/classes/.
But when I execute:
mvn clean compile dependency:unpack
I get:
Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.10:unpack (default-cli) on project simple: Either artifact or artifactItems is required -> [Help 1
I have verified that the dependencies are available in my local repository.
In my example pom below I've used junit as an example, but no matter which dependency I list, I get the same error.
pom.xml:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/classes/externaltools</outputDirectory>
<includes>**/*.txt</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>

The issue is due to you cannot use mvn clean compile dependency:unpack and <executions> tags together.
In documentation Maven Depdendency Plugin at the bottom part of the page you can read:
If you intend to configure this mojo for execution on the command line using: mvn dependency:unpack you must not put the configuration inside the executions tag. Your configuration should look like this:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<configuration>
<artifactItems>
<artifactItem>
<groupId>[ groupId ]</groupId>
<artifactId>[ artifactId ]</artifactId>
<version>[ version ]</version>
<type>[ packaging ]</type>
<classifier> [classifier - optional] </classifier>
<overWrite>[ true or false ]</overWrite>
<outputDirectory>[ output directory ]</outputDirectory>
<destFileName>[ filename ]</destFileName>
<includes>[ comma separated list of file filters ]</includes>
<excludes>[ comma separated list of file filters ]</excludes>
</artifactItem>
</artifactItems>
<!-- other configurations here -->
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
I have tried removing the <execution> tags and works perfectly!

Related

mvn serenity:aggregate runs 0 tests and index.html has 0 results however mvn clean verify works and gets results

We have Serenity Cucumber integrated with Maven for REST API automation project running with Junit. Whenever trying to execute the command mvn serenity:aggregate results on console shows "Build success' but with 0 requirements loaded and index.html has 0 results and generated under target/site/serenity. Whereas if run with the command mvn clean verify getting results under the same folder.
pom.xml file of plugin:
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>2.0.40</version>
<dependencies>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>2.0.40</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>4.5.0</version>
<dependencies>
<dependency>
<groupId>com.googlecode.totallylazy</groupId>
<artifactId>totallylazy</artifactId>
<version>1.20</version>
<scope>system</scope>
<systemPath>${basedir}/externalMavenLibrary/totallylazy-1.20.jar</systemPath>
</dependency>
</dependencies>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>cucumber-jvm-example</projectName>
<outputDirectory>${basedir}/target/site/cucumber-pretty</outputDirectory>
<jsonFiles>
<param>**/*.json</param>
</jsonFiles>
<classificationFiles>
<param>**/*.properties</param>
</classificationFiles>
<cucumberOutput>${basedir}/target/cucumber.json</cucumberOutput>
<enableFlashCharts>true</enableFlashCharts>
<checkBuildResult>true</checkBuildResult>
<skippedFails>true</skippedFails>
</configuration>
</execution>
</executions>
</plugin>
Other versions in the pom.xml file:
serenity-cucumber: 1.9.35
serenity-rest-assured: 2.0.45
serenity-core: 2.0.45
serenity-junit: 2.2.1
serenity-maven-plugin: 2.0.40
Serenity.properties file:
serenity.project.name=Test
serenity.console.colors=true
serenity.reports.show.step.details=true
Since unable to get report after running mvn serenity:aggregate, missing graphs and other nice features.
Please guide.
Able to figure out the reason why the command was not working. in pom.xml file, after adding tags and while running the command by giving the report output path, I am able to get the Serenity reports as expected.
updates done:
serenity.test.root="com.projectname.backend.core"
serenity.reports.show.step.details=true
serenity.outputDirectory = target/site/reports
in pom.xml file: added tags configuration, and the tag has value in RunnerFile.java
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.maven.version}</version>
<configuration>
<tags>${tags}</tags>
</configuration>
Also, below dependency versions used:
<properties>
<serenity.version>2.2.1</serenity.version>
<serenity.cucumber.version>2.2.0</serenity.cucumber.version>
<serenity.maven.version>2.2.1</serenity.maven.version>
</properties>
Command used:
mvn serenity:aggregate -Dserenity.outputDirectory=C:\Users\projectname\target\site\reports
I encoutred this problem and my error was that I forgot to name scenario in the feature file. So check this part

How to configure PMD violation threshold in Jenkins

I have created a jenkins job and below is the pom file.
1. Can you please suggest a way to ignore a certain 'X' number of PMD violations?
2. Is this setup correct to generate PMD reports? Goal in Jenkins is clean install pmd:check site
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<linkXRef>false</linkXRef>
<!--<targetJdk>1.6</targetJdk>-->
<failOnViolation>true</failOnViolation>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<linkXRef>false</linkXRef>
<!--<targetJdk>1.6</targetJdk>-->
<failurePriority>5</failurePriority>
<failOnViolation>true</failOnViolation>
<targetDirectory>./pmdOutput</targetDirectory>
<rulesets>
<ruleset>/rulesets/basic.xml</ruleset>
</rulesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</reporting>
The PMD Maven plugin doesn't allow to setup thresholds on number of violations, it either fails at the first violation of the given priority, or it doesn't.
What I would probably do is not run the pmd:check target, but have maven generate the reports, and use the Jenkins' PMD plugin to parse the report xml and fail the build if needed.
The PMD plugin for Jenkins does allow more flexible threshold configuration.
Since version 3.10.0, PMD has configuration option maxAllowedViolations:
https://maven.apache.org/plugins/maven-pmd-plugin/cpd-check-mojo.html#maxAllowedViolations
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<maxAllowedViolations>180</maxAllowedViolations>
</configuration>
</plugin>

Maven Javadoc Plugin During Site Goal: javadoc: error - java.lang.OutOfMemoryError: Please increase memory

I have been struggling to increase the memory of my javadoc plugin via my pom file. For some reason my Mac build slave fails during the site goal with an OutOfMemoryError. I tried adjusting the maxmemory of the javadoc plugin via my pluginManagement section of the pom (as per the maven-javadoc-plugin documentation):
...
<build>
...
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<maxmemory>512m</maxmemory>
</configuration>
</plugin>
</plugins>
<pluginManagement>
...
</build>
...
This didn't seem to help anything, my build still failed with an out of memory error.
So I decided to put this directly in my plugin declaration instead (see the build-plugins-plugin section below:
...
<build>
...
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
</plugin>
...
</plugins>
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<maxmemory>512m</maxmemory>
</configuration>
</plugin>
...
</plugins>
...
</build>
...
...and yet this is still not working, the Mac build slave still fails during the site goal.
It turned out I was being an idiot. The site goal uses the plugin defintions declared in the reporting section of the pom. Therefore I had to add my max memory configuration here instead, see below:
...
<build>
...
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
</plugin>
</plugins>
<pluginManagement>
...
</build>
...
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<maxmemory>512m</maxmemory>
</configuration>
</plugin>
</plugins>
</reporting>
...
Based on this result, it is my assumption that Maven will not pick up configuration details defined in the build-pluginManagement section of the pom for plugins defined in the reporting section. Cheers.

gmaven grails project not using maven-war-plugin

I'm having issues with a filtered context.xml file being packaged in a mvn grails:war execution.
I have it working when you do mvn war:war but doing that doesn't create my grails application war. When running mvn grails:war I don't get the context.xml file. Is this a case of the grails:war target not running the maven-war-plugin? I'm getting no errors. Any help is appreciated. Here are my relevant pom settings:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/webapp/META-INF</directory>
<filtering>true</filtering>
<targetPath>META-INF</targetPath>
<includes>
<include>**/context.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.grails</groupId>
<artifactId>grails-maven-plugin</artifactId>
<version>1.3.4</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>init</goal>
<goal>maven-clean</goal>
<goal>validate</goal>
<goal>config-directories</goal>
<goal>maven-compile</goal>
<goal>maven-test</goal>
<goal>maven-war</goal>
<goal>maven-functional-test</goal>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
...
<filters>
<filter>${basedir}/src/main/filters/dev.properties</filter>
</filters>
grails:war uses grails command so generate war, so it will ignore anything you configured in the "maven war plugin". You will have to configure it within grails.

How can I deploy a zip file created with the maven-antrun-plugin?

I'm using the maven-antrun-plugin to do a bunch of work with Ant, which ultimately results in a zip file. I'd like to deploy the zip file to our maven server (Artifactory). The maven-antrun-portion works as intended and successfully creates the zip file; however deployment fails with the following error message:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.6:deploy (default-deploy) on project projectname: The packaging for this project did not assign a file to the build artifact
My POM file is as follows:
<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.company.division</groupId>
<artifactId>projectname</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>com.company.product</groupId>
<artifactId>parentproject</artifactId>
<version>1.0.0</version>
</parent>
<distributionManagement>
<snapshotRepository>
<id>artifactory</id>
<name>artifactory-snapshots</name>
<url>http://localartifactoryserver/artifactory/libs-snapshot-local</url>
<uniqueVersion>false</uniqueVersion>
</snapshotRepository>
</distributionManagement>
<dependencies>
<!-- Some dependencies... -->
</dependencies>
<build>
<plugins>
<!-- Compiler plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF8</encoding>
<optimize>true</optimize>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<target>
<!-- Do lots of other stuff with Ant. -->
<!-- Create a zip file. -->
<zip basedir="mydir" destfile="${WORKSPACE}/MyZip.zip" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.6</version>
<configuration>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<packaging>zip</packaging>
<file>MyZip.zip</file>
<url>${project.distributionManagement.snapshotRepository.url}</url>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I invoke this (from the parent POM) with mvn -U -pl projectname clean deploy I get the aforementioned error during the deploy phase. Does anyone know what I'm doing wrong or how I can fix this?
The solution that worked for me (I'm not sure if it is ideal, it seems rather hackish) was to switch to the deploy:deploy-file goal:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.6</version>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<repositoryId>artifactory</repositoryId>
<packaging>zip</packaging>
<generatePom>true</generatePom>
<url>${project.distributionManagement.snapshotRepository.url}</url>
<artifactId>${project.artifactId}</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<file>${WORKSPACE}/MyZip.zip</file>
</configuration>
</plugin>
and invoke it explicitly:
mvn -U -X -pl projectname clean install deploy:deploy-file
The solution worked for me is to add the <attachartifact> tag after zip creation, filled with the same path and zip filename . So something like:
<executions>
<execution>
<id>zip-artifacts</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<zip destfile="${project.build.directory}/MyStuff-${project.version}.zip" update="true" comment="This is my comment...">
<fileset dir="${project.build.directory}/MyStuff" />
</zip>
<attachartifact file="${project.build.directory}/MyStuff-${project.version}.zip" type="zip" />
</target>
</configuration>
</execution>
</executions>
Remember that the zip file has to exists, otherwise attachartifact returns "file does not exists" error (consider to use whenempty="create" in tag in order to avoid errors).
While looking for a way to add comment to a zip file I found this question. The deploy worked fine but had troubles with the maven release to post into nexus. The solution below solved my problem, I made an empty zip assembly and then simply replaced it with the zip file from the ant task which allowed me to add the comment to the zip file.
This way the artifact is generated and not transitive.
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<id>${project.build.finalName}</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/MyStuff/emptydir</directory>
<outputDirectory></outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
<plugin>
<!-- make an assembly (zip the LxBase) for the distribuition -->
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>docs-assembly</id>
<phase>package</phase>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/assemble.xml</descriptor>
</descriptors>
</configuration>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>zip-artifacts</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<zip destfile="${project.build.directory}/MyStuff-${project.version}.zip" update="true" comment="This is my comment...">
<fileset dir="${project.build.directory}/MyStuff" />
</zip>
</target>
</configuration>
</execution>
</executions>
</plugin>

Resources