How to make code coverage from FlexUnit work with Sonar? - maven

Situation
I'm trying to get Sonar display the code coverage reports generated by FlexUnit from a Maven build job using Flex-Mojos but I'm not having any luck - all I ever get is a frustrating "-".
Build output
The result is that the dashboard always shows this (the left column):
(no, the unit tests don't run for over 90 minutes but rather 16 seconds; don't know what's off here)
The Sonar related console output is this:
So everything seems to work fine (no file-not-found errors other than the Cobertura one which I can't seem to get rid of in any way, no parse exceptions, etc).
Build setup
The pom.xml used for building the project looks like this:
<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>
<parent>
<groupId>foo</groupId>
<artifactId>parent</artifactId>
<version>1.0.3</version>
</parent>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>swc</packaging>
<name>Bar</name>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito</artifactId>
<version>1.4M5</version>
<type>swc</type>
<scope>external</scope>
</dependency>
<dependency>
<groupId>com.adobe.flexunit</groupId>
<artifactId>flexunit</artifactId>
<version>4.1.0-8</version>
<classifier>flex</classifier>
<type>swc</type>
<scope>external</scope>
</dependency>
</dependencies>
<build>
<testSourceDirectory>src/test/flash</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>4.2-beta</version>
<configuration>
<coverage>true</coverage>
<debug>false</debug>
<optimize>true</optimize>
<omitTraceStatements>true</omitTraceStatements>
<verboseStacktraces>false</verboseStacktraces>
<defines>
<property>
<name>CONFIG::BUILD</name>
<value>"${project.version}"</value>
</property>
</defines>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>asdoc</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>${project.build.directory}/asdoc/tempdita</directory>
<targetPath>docs</targetPath>
<includes>
<include>**/*.xml</include>
</includes>
<excludes>
<exclude>ASDoc_Config.xml</exclude>
<exclude>overviews.xml</exclude>
</excludes>
</resource>
</resources>
</build>
<properties>
<sonar.language>flex</sonar.language>
<sonar.sources>src/main/flash</sonar.sources>
<sonar.tests>src/test/flash</sonar.tests>
<sonar.surefire.reportsPath>target/surefire-reports</sonar.surefire.reportsPath>
</properties>
</project>
I've tried several ways to run Sonar:
dynamicAnalysis=reuseReports + mvn clean install + mvn sonar:sonar
dynamicAnalysis=true + mvn clean install sonar:sonar -Dmaven.test.failure.ignore=true
dynamicAnalysis=true + mvn clean install -DskipTests=true + mvn sonar:sonar (<-- doesn't work: for some reason in this scenario the unit tests fail to run with a NullPointerException during execution of Flex-Mojos's test-run goal).
Is there a way to make displaying the coverage results in the Sonar dashboard work? Do I need additional plugins for that (Emma, Clover, whatever) to get the coverage from the standard Surefire reports to show up? Is there a known issue that prevents this from working? Am I doing something wrong?
Update
I've tried running Sonar with the Sonar-Runner. Interestingly, the dashboard then completely drops the code coverage widget. Checking the console output of the runner shows that the runner doesn't execute the FlexSurefireSensor (which the sonar:sonar Maven goal does):
The sonar-project.properties file contains:
sonar.projectKey=foo:bar
sonar.projectName=Bar
sonar.projectVersion=0.1.0-SNAPSHOT
sonar.language=flex
sources=src/main/flash
tests=src/test/flash
sonar.dynamicAnalysis=reuseReports
sonar.surefire.reportsPath=target/surefire-reports
I'm running it with mvn clean install followed by sonar-runner.

To get code coverage, you need to add the following property:
<sonar.cobertura.reportPath>target/site/coverage-cobertura/coverage.xml</sonar.cobertura.reportPath>
(or whatever the path to your coverage file is).
This is documented on the plugin home page.

I think the property you are missing in your POM is sonar.dynamicAnalysis:
<properties>
..
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.surefire.reportsPath>target/surefire-reports</sonar.surefire.reportsPath>
</properties>
The Flex plugin documentation describes how to enable Unit test and code coverage reporting. It also recommends using the Java Runner, but it should be functionally similar to the Maven plugin launcher.

Related

wildfly.maven.plugin deploys nothing if packaging is set to pom

I am using Maven in order to automatically download a dependency, set up (and start) the JBoss server and deploy that downloaded dependency there. I created a pom.xml, which uses several Maven-Plugins. For JBoss-related interactions I am using the wildfly-maven.plugin (currently version 2.0.1.Final).
Since I am not building an artifact, but rather downloading it, I am not really producing a JAR (or any archived artifact).
The problem I currently have is: the wildfly-maven-plugin does not seem to do anything if packaging is set to pom.
As a workaround I currently set the project packaging to JAR and added the following to prevent the project JAR from building:
<properties>
<jar.skipIfEmpty>true</jar.skipIfEmpty>
<maven.install.skip>true</maven.install.skip>
</properties>
Update 04.03
This is what my pom.xml basically looks like:
<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>some.group</groupId>
<artifactId>artifact</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>~y</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.install.skip>true</maven.install.skip>
<jar.skipIfEmpty>true</jar.skipIfEmpty>
<plugin.wildfly.version>2.0.1.Final</plugin.wildfly.version>
<plugin.wildfly.jboss-home>D:\server\jboss-eap-7.1</plugin.wildfly.jboss-home>
<plugin.wildfly.hostname>localhost</plugin.wildfly.hostname>
<plugin.wildfly.port>9990</plugin.wildfly.port>
<plugin.wildfly.debug.port>9991</plugin.wildfly.debug.port>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${plugin.wildfly.version}</version>
<configuration>
<jboss-home>${plugin.wildfly.jboss-home}</jboss-home>
<id>local-jboss</id>
<hostname>${plugin.wildfly.hostname}</hostname>
<port>${plugin.wildfly.port}</port>
<filename>y.ear</filename>
<force>true</force>
</configuration>
<executions>
<execution>
<id>deploy-ear</id>
<phase>install</phase>
<goals>
<goal>deploy-only</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I will give deploy-artifact a try, but in general I'd expect the wildfly.maven.plugin to work even if <packaging> is set to pom.
Maven command on commandline to build it: mvn clean install.
My real pom.xml is a bit more complex, but if it'd work using this simple pom.xml, I could make it work in the more complex one that I use.
Have a look at the deploy-artifact goal. There is an example of it in the documentation.
wildfly-maven-plugin does not seem to do anything if packaging is set to pom. Using the packaging-type jar along with jar.skipIfEmpty helps.
When using wildfly-maven-plugin's deploy-only goal, publishing works (through the management interface).

How does maven decide when to use the target folder for classpath

I have a question regarding how maven calculates the classpath during building. Specifically, what controls when the "target/classes" is used and when the "jar" from a repository (local/remote) is used.
I have a project on version 1.0.0-SNAPSHOT where the artifacts have NOT been installed/deployed so there is no "jar" in some repository (remote or local) to resolve them. I want to run "generate-sources" WITHOUT installing locally (no 'mvn install' run).
The structure looks like this:
parent-prj
parent-prj/sub-prj
parent-prj/gen-src-prj <--- This depends on 'sub-prj'
When I run "mvn -am -pl parent-prj/gen-src-prj generate-sources" in order to just generate some java files, it does not work:
[ERROR] Failed to execute goal on project gen-src-prj: Could
not resolve dependencies for project
mygrp:gen-src-prj:jar:1.0.0-SNAPSHOT:
Could not find artifact
mygrp:sub-prj:jar:1.0.0-SNAPSHOT -> [Help 1]
Using debug output and adding "dependency:build-classpath" I can confirm that maven ignores the presence of "sub-prj" in the reactor and looks for a "jar" somewhere which it can't find. Yet the project is printed in the reactor summary:
[INFO] Reactor Summary:
[INFO]
[INFO] parent-prj ..................................... SUCCESS [ 0.625 s]
[INFO] sub-prj ........................................ SUCCESS [ 0.018 s]
[INFO] gen-src-prj .................................... FAILURE [ 0.040 s]
The interesting thing I noticed is that running the compile goal works fine! This uses sub-prj/target/classes (as shown by dependency:build-classpath) and has no trouble generating the sources and even compiling them: "mvn -am -pl parent-prj/gen-src-prj compile"
So here are the points I want to understand:
Why does the compile goal work but the generate-sources doesn't work?
At what point does maven decide to use the output folder of previous projects on the reactor classpath instead of looking for a jar?
Is there a way for generate-sources to run directly as I want it EVEN WITHOUT having its dependencies resolved?
Regarding (3) my generation tool is a utility invoked by:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
The tool reads some XML in src/main/resources and generates Java files and does NOT need anything in its class-path (so there is no need for maven to resolve it).
Also note that I would be interested to understand (1) and (2) even if a solution for (3) is provided.
EDIT: Per comment request, adding full example
parent-prj/pom.xml
<?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>mygrp</groupId>
<artifactId>parent-prj</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>sub-prj</module>
<module>gen-src-prj</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.9</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
parent-prj/sub-prj/pom.xml
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>mygrp</groupId>
<artifactId>parent-prj</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>sub-prj</artifactId>
</project>
parent-prj/gen-src-prj/pom.xml
<?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>
<parent>
<groupId>mygrp</groupId>
<artifactId>parent-prj</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>gen-src-prj</artifactId>
<dependencies>
<dependency>
<groupId>mygrp</groupId>
<artifactId>sub-prj</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<includeProjectDependencies>false</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
<mainClass>uk.co.real_logic.sbe.SbeTool</mainClass>
<systemProperties>
<systemProperty>
<key>sbe.output.dir</key>
<value>${project.build.directory}/generated-sources/java</value>
</systemProperty>
<systemProperty>
<key>sbe.validation.warnings.fatal</key>
<value>true</value>
</systemProperty>
</systemProperties>
<arguments>
<argument>${project.build.resources[0].directory}/Examples.xml</argument>
</arguments>
<workingDirectory>${project.build.directory}/generated-sources/java</workingDirectory>
</configuration>
<dependencies>
<dependency>
<groupId>uk.co.real-logic</groupId>
<artifactId>sbe-tool</artifactId>
<version>1.7.10</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/java/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
EDIT: Armed with the knowledge from the answers I have come up with this workaround that allows one to achieve the desired behaviour. I list the dependencies in a profile that is active by default, then use another profile to run generate-sources with no dependencies active, like follows:
parent-prj/gen-src-prj/pom.xml
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>mygrp</groupId>
<artifactId>sub-prj</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>excludeDependency</id>
<dependencies>
</dependencies>
</profile>
</profiles>
To generate sources with above, use: mvn -PexcludeDependency generate-sources
Maven can reference only output generated in current Session (during currently executing shell command). It uses the most "mature" place to look for the "output":
If compile is run - the classes end up in the target/classes dir, thus other modules can reference that
If package is run - then target/*.jar is created and this jar file ends up in the classpath instead
If install is run - then jar file ends up in the local repository - which is what ends up on the classpath
So there are 3 factors that impede your task:
maven-exec-plugin requires dependency resolution (as pointed out by #mondaka)
Your module1 references module2
generate-sources is run before the compilation. Thus module2 is not yet prepared to be used as a dependency.
So if you want to do it your way - you'll have to run at least compile phase each time you use anything from the Default Lifecycle. Or you could write your own plugin that doesn't require dependency resolution.
This problem is related to an open maven bug:
https://issues.apache.org/jira/browse/MNG-3283
The issue says: "The problem only occurs when a plugin binds itself to the
generate-sources phase and has #requiresDependencyResolution".
I have checked that exec-maven-plugin Mojo have indeed requiresDependencyResolution = ResolutionScope.TEST. You can see that on https://github.com/mojohaus/exec-maven-plugin/blob/master/src/main/java/org/codehaus/mojo/exec/ExecJavaMojo.java
Then, your only option is to use compile or process-classes phases. This is a Major open bug from 2007...

Sending email with attachment using Maven

Using surefire plugin and postman plugin, I am able to generate a surefire report and send email to a recipient. But the surefire report (html) is not getting attached with the email. Recipient is getting an email without the attachment. If I run the project again, email has been delivered with the attachment. Following is my pom.xml. I don't know what I am missing. Please help.
<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.testing.example</groupId>
<artifactId>SampleExample</artifactId>
<packaging>jar</packaging>
<name>SampleExample</name>
<version>1.0.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>ch.fortysix</groupId>
<artifactId>maven-postman-plugin</artifactId>
<version>0.1.6</version>
<executions>
<execution>
<id>send_an_mail</id>
<phase>test</phase>
<goals>
<goal>send-mail</goal>
</goals>
<inherited>false</inherited>
<configuration>
<from>xxxxxxxxxx</from>
<subject>this is a test auto email sent from Eclipse using Maven</subject>
<htmlMessage>
<![CDATA[
<p>Hi, Please find attached.</p>
]]>
</htmlMessage>
<failonerror>true</failonerror>
<mailhost>smtp.gmail.com</mailhost>
<mailport>465</mailport>
<mailssl>true</mailssl>
<mailAltConfig>true</mailAltConfig>
<mailuser>xxxxxxx</mailuser>
<mailpassword>xxxxxxx</mailpassword>
<receivers>
<receiver>xxxxxxxxx</receiver>
</receivers>
<fileSets>
<fileSet>
<directory>${basedir}/target/site</directory>
<includes>
<include>**/surefire-report.html</include>
</includes>
</fileSet>
</fileSets>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
Generally, I find that it is more helpful to get a Maven build working from the command line before attempting to introduce Eclipse.
Do you have a remote repository set up (e.g. Nexus, Artifactory)? If not, it would be good to have that in place if you are going to continue to use Maven regularly. Once the remote repo exists, then you will need to configure the project's distributionManagement element in order to publish artifacts to that repository.
Now, back to your original question. surefire-report:report is a report goal, and runs as part of the reporting lifecycle by default. As you have it configured, it is not related to the build lifecycle in any way. In your POM, the postman plugin is bound to the test phase, which is part of the default lifecycle.
When you run command mvn surefire-report:report per the documentation Maven runs the build lifecycle up to and including the test phase. (The key phrase in the documentation is "Invokes the execution of the lifecycle phase test prior to executing itself.").
So, the order of operations when you run mvn surefire-report:report is:
Maven forks a 'mvn test' build behind the scenes
postman:send-mail runs as part of test phase
surefire-report:report creates the reports
Note how the last two steps are out of order. So, the first time you run the command, there are no test reports yet, and thus no attachment. The second time you run it, there are reports from the previous build that get attached.
The question for you becomes, do you plan to run this at the command line once in a while in order to send reports when someone asks for them? If so, then you may simply remove the phase configuration from the postman plugin and use Maven command mvn surefire-report:report postman:send-mail. This will perform the steps in the correct order.
If you want the email to happen every time (i.e. with every mvn clean install site), you need to bind the postman:send-mail goal to a phase that runs after the reports are generated. I would try the site phase. If that doesn't work, then use post-site and change the Maven command to mvn clean install post-site.
P.S. If you're new to Maven, I highly recommend learning about the different lifecycles and the difference between a phase and a goal. You can't really use Maven effectively without that knowledge.
Just change the order of plugin.
Maven compiler plugin
Surefire report plugin
Postman plugin
This will help and you can run it as you wish.

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.

sonar findbug missing class exception

while I am using sonar findbug for code review, it throws exception, claiming some classes are missing.
After some research, it's clear that the jars needed to build the project, should be included in the pom.xml for sonar's use.
to do that, sonar official web site suggesting, add dependencies,
com.opensymphony
xwork-core
2.1.6
system
${basedir}/.../xwork-core.jar
however, for me, it's always not working.
I am using windows, would anyone please enlighten me, how to configure, especially the systempath?
Here is the pom.xml, for one module of the project.
<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>DB</groupId>
<artifactId>Project1</artifactId>
<name>project1</name>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>com.opensymphony</groupId>
<artifactId>xwork-core</artifactId>
<version>2.1.6</version><!--installed into .m2 folder, local repository, then refer it-->
</dependency>
<dependency>
<groupId>dep</groupId>
<artifactId>dep1</artifactId>
<version>1.0</version> <scope>system</scope>
<systemPath>${basedir}/lib//asn.jar</systemPath>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<outputDirectory>build-to/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<excludes>
<exclude>**/*.*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<sonar.dynamicAnalysis>false</sonar.dynamicAnalysis>
</properties>
</project>
Thanks,
Jackie
Is your project already a maven project, or are you compiling things with ant or some other tool and then trying to get sonar to run against it? Sonar Light mode can be tricky with very complex projects. If you've got a multi-module project, i'd get the simplest project working under a local copy of sonar and then work towards adding more modules.
Additionally, I would try copying the files locally to a different directory that does not step up from ${basedir}. See if that helps. So ${basedir}/lib/xwork-core.jar something like that.
Perhaps for Sonar analysis, you can have a separate task copy the needed libraries to a temp folder that can be accessed appropriately, and then remove them once the analysis is complete.
i found out the problem. The official documentation of sonar is actually wrong.
"mvn sonar:sonar" would invoke the maven sonar plugin 2.0 beta, which won't enable the dependency of library jars work. Instead, call "mvn sonar3:sonar", invoke the maven sonar plugin 2.4.1, the latest version, works.

Resources