Im facing the following problem. I have set up my checkstyle with the following configuration:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.plugin.version}</version>
<inherited/>
<configuration>
<configLocation>${basedir}/checkstyle.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>
</plugins>
</reporting>
This runs fine when I run mvn site. However, when I run checkstyle through mvn checkstyle:checkstyle in order to get the XML report much more efficiently, the checkstyle plugin fails back to use the default configuration. When I move the plugin to <build> the XML is generated properly, but now the checkstyle report is not included in the generated site anymore.
What is the (current) way of setting up report plugins as Checkstyle, while perserving the ability to run the plugin separately under the same configuration?
Is it really the preferred way to defined your plugins and configuration twice?
Okay, apparently you should add the plugin with configuration to both <build> and <reporting>.
Related
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
What is the point of using maven in intellij if it dose not work without setting the correct JDK under various intellij options?
What I mean is that now with intellij I have to set the JDK in 3 different places.
File->Setting->Build->Compiler
File->Project Structure->Project
File->Project Structure->Modules
While I aspect expect that when i compiler on the right side where are the maven options it works just by watching the pom file.
i think that depends on what type of project you want to make but personally i find maven nice to use because you can set up several actions in the pom file (for example when compiling Less files, excluding them from the build and just using the resulting css files).
another feature would be the easy way to add dependency's from the maven rep http://mvnrepository.com/
I have a running maven project with JUnit tests. The Maven Surefire Plugin drops xml files after the tests. These xml files include, besides properties and logprints, following information:
<testcase xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="methodNameForTest"
classname="com.my.test.project.Testclass"
time="20.931">
<error type="java.lang.NullPointerException">java.lang.NullPointerException</error>
</testcase>
Can someone explain me the usual way how data gets written from JUnit into these brackets and how more data can be added to it?
File search with these words doesn't help btw. Can't find anything in my project.
Thank you in advance
You cannot add custom messages into the XML report generated by the maven-surefire-plugin. The closest you can get is by configuring this plugin to redirect your System.out.println() calls to a text file. This is configured in your pom.xml with the help of redirectTestOutputToFile configuration, as shown below:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
</configuration>
</plugin>
</plugins>
</build>
By default, this would create target/surefire-reports/<test-name>-output.txt. Any calls to System.out.println(...) from your tests would get redirected to this file.
I'm having difficulty trying to add an argument to the jvm. It looks like using surefire is the only way to do this. My current code in the pom.xml is
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<argLine>-Xmx512m</argLine>
<systemPropertyVariables>
<all.clusters>${all.clusters}</all.clusters>
<branding.token>${brandingToken}</branding.token>
</systemPropertyVariables>
</configuration>
</plugin>
Maven is new to me so perhaps I'm missing something simple.
Running in a Netbeans 8.1 environment.
Turns out that what I needed to do was not to get surefire to run with special arguments, because that only covers tests. The trick to getting it working was the fact that this project is a NetBeans application which uses the
nbm-maven-plugin.
The following blog post describes how to modify the arguments.
Blogpost
When building WAR package using Maven 2.1.1, I get this warning message:
[WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ig
nored
(webxml attribute is missing from war task, or ignoreWebxml attribute is specifi
ed as 'true')
Is there a way to eliminate it? It doesn't fail the building process, but I just do not want to see it.
It seems to be fixed in current version of maven-war-plugin, so just specifying:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
</plugin>
fixed it for me. (See the last answer (20/Sep/12 4:37 AM) from Anders Hammar on https://issues.apache.org/jira/browse/MWAR-248.)
I got rid of this warning in maven 3.0.1 with the following build configuration (i believe perhaps web.xml is added to the project by other means, and should't be packaged by default):
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<packagingExcludes>WEB-INF/web.xml</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
I've filed the following bug report regarding this issue: https://issues.apache.org/jira/browse/MWAR-248
I need to setup Maven plugins. I have downloaded the JARs. Can anyone please tell me what do I do next in order to integrate or setup the plugins with Maven?
Should I copy the JARs into the parent directory or do I need to edit any file?
The plugins are:
Java2HTML
JDepend
Checkstyle
Clover
Cobertura
EMMA
Findbugs
JavaNCSS
PMD
QALab
Xradar
Sonar
If Maven has access to the central repository it will download most plugins (some are not hosted on central, to access those you need to define an additional repository in your pom or settings).
If the dependencies are configured in your POM, Maven will automatically attempt to download them when you run a relevant goal. For the dependencies you listed this is mvn site.
The majority of those jars you've listed are reports, so should be declared in the reporting section of the POM, for example (I would also declare the versions to be sure you're getting the expected plugin):
<reporting>
<plugins>
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
<configuration>
<linkXref>true</linkXref>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
<outputDirectory>target/site/cobertura</outputDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-report-plugin</artifactId>
<configuration>
<outputDirectory>${basedir}/target/surefire-reports</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jdepend-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<configuration>
<xmlOutput>true</xmlOutput>
<effort>Max</effort>
</configuration>
</plugin>
</plugins>
</reporting>
Some background on Maven's plugin execution model:
When you run mvn site, this is short hand for "run the site goal from the latest version of the site plugin", i.e. it is equivalent to mvn site:site, which is in turn shorthand for mvn org.apache.maven.plugins:maven-site-plugin:LATEST:site
Maven will attempt to contact the central repository, determine the LATEST version from the maven-metadata.xml, then download it (and any of its dependencies that are also missing) before executing it.
If you are behind a proxy you may see an error message in your build log like this:
[INFO] The plugin 'org.apache.maven.plugins:maven-site-plugin' does not exist or no valid version could be found
To address this you can declare proxy settings in your Maven settings.xml (in [MVN_HOME]/conf/settings.xml). They are commented out by defualt, but look something like this:
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net,some.host.com</nonProxyHosts>
</proxy>
Replace the username, password, host, and port values with the relevant for your environment and Maven will be able to download the required dependencies.
For more details on using Maven, check out the Maven: The Definitive Guide by Sonatype, it is online and free.
Sirakov is right; Maven will download and install the plugins automatically when they are used.
You can either run them directly (for one-off jobs), or configure them in your pom.xml - this also allows you to configure then, and set the to run automatically, for example, to generate source code or report on test coverage. A major advantage of this is that you can define a single set of plugin configs in a shared parent pom, and reuse the same configurations across across all your projects, while still being able to override the inherited configuration in each subproject where necessary - this is one of the biggest advantages of using Maven on larger projects.
Each plugin has its own configuration parameters, the standard ones are documented at http://maven.apache.org/plugins/. Another good resource is the O'Reilly Maven book, online at http://www.sonatype.com/books/maven-book/reference/
An example configuration for cobertura:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.3</version>
<configuration>
<outputDirectory>${project.build.directory}/pmd</outputDirectory>
<targetDirectory>${project.build.directory}</targetDirectory>
<aggregate>true</aggregate>
<!-- CPD minimum tokens to report on (5 to 10 duplicate lines) -->
<minimumTokens>100</minimumTokens>
<minimumPriority>3</minimumPriority>
<!-- Exclude mock classes -->
<excludes>
<exclude>**/Mock.*</exclude>
<exclude>**/Dummy.*</exclude>
<exclude>**/*Mock.java</exclude>
<exclude>**/*Dummy.java</exclude>
</excludes>
<includeTests>true</includeTests>
<targetJdk>1.5</targetJdk>
<rulesets>
<ruleset>pmd_ruleset.xml</ruleset>
</rulesets>
</configuration>
</plugin>
You don't need to download the plugins manually. I'm not 100% sure, but if you want to use for example the checkstyle plugin, you need to start maven with checkstyle parameter form command line
something like:
mvn checkstyle:checkstyle
or
mvn checkstyle:check
edit1: But you can also put the jars into the local m2 repository with the specific folder structure to access them.
edit2: you can put all your plugins into your own repository and then you need to tell maven (using the pom), which repositories you want to use. Every plugin must be described in the pom.