How to ignore Element is not allowed here Error - maven

I have always had an issue of being warned that following code in my maven POM file is not allowed here. (No issues when I used Eclipse in the past).
But I could still compile and run without issues using Intellij 2017 version.
I recently moved to version 2018. Getting same warnings but no longer able to compile. (If I comment it out, compiles fine).
Is there a work around for this on Intellij? It is legacy code and I do not want to remove it.
Error messages:
Element compilerArgs is not allowed here.
Element forkCount is not allowed here.
POM file. Commented parts with issue.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgs> <!-- ERROR -->
<arg>-XX:MaxPermSize=256m</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>1</forkCount> <!-- ERROR -->
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
</configuration>
</plugin>

Related

How to configure SpotBugs maven plugin to create a full report but check for high threshold only?

I have a legacy maven project and want to integrate the FindBugs successor SpotBugs to create a report of all issues but fail if there a High priority issues only (for now).
It is easy to create the report only without fail ing or to fail on a specific threshold. But when specifying a threshold all issues below that one are also removed from the report.
I have tried to configure the plugin according to to documentation but without success:
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.3</version>
<configuration>
<effort>Max</effort>
<threshold>High</threshold>
<xmlOutput>true</xmlOutput>
<spotbugsXmlOutputDirectory>${project.build.directory}/spotbugs-reports</spotbugsXmlOutputDirectory>
<xmlOutputDirectory>${project.build.directory}/spotbugs-reports</xmlOutputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
I am using Maven 3 and SpotBugs 3.1.3.
Not sure if that helps, it's mostly a workaround.
I have a similar case and what I did was that I placed the configuration in a "reporting" tag (not reportSets). In the "build" tag, I just put the plugin information and the dependencies. The configuration used the default values for the output xml and output folder. I also added file which was filtering out some of the bugs:
<build>
<plugins>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.10</version>
<dependencies>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>3.1.11</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.10</version>
<configuration>
<excludeFilterFile>spotbugs_filter.xml</excludeFilterFile>
</configuration>
</plugin>
</plugins>
</reporting>
I then did a
mvn clean install site spotbugs:check
This gave me:
a spotbugsXml.xml file in the build_directory containing ALL of the bugs found (no filters applied).
a report spotbugs.html was produced in target/site which contained the filtered list of bugs.
So, to link this with your issue, I guess that using these "steps" you can have two reports, one with the threshold and another one without.
Does this make sense?

comma separated parametrized maven ONLY tests one testng file

I am facing an issue with Maven which nowhere on internet I could find an answer for it. appreciate if anyone can help me with it. I aiming to test 2 testng files sent as parameter to POM as:
mvn clean test -DsuiteXmlFiles=1.xml,2.xml
and the POM file is:
<plugins>
<!-- Following plugin executes the testng tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<!-- Suite testng xml file to consider for test execution -->
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<!-- Compiler plugin configures the java version to be usedfor compiling
the code -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
but, when i run, it ONLY runs the 2.xml file and runs it twice!!!
tried many options but no matter what is the second xml file it totally ignores the first and runs the second one twice.
can anyone please help?
thanks
Your surefire plugin should look like below
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<suiteXmlFiles>${file}</suiteXmlFiles>
<skipTests>false</skipTests>
</configuration>
</plugin>
Pay close attention to <suiteXmlFiles>${file}</suiteXmlFiles>
So now you can pass in multiple suite files via
mvn clean test -Dfile=src/test/resources/suite-one-with-execution.xml, src/test/resources/suite-two-with-execution.xml
For more details you can refer to my blog post here.
finally understood where the issue was, for some reason i still dont know why, the Suite name in xml files should be not same as each other!!

Maven where is it looking for the JDK?

4th time typing this message up as this crappy machine I am to use crashes randomly throughout the day. Gotta love it.
My development environment JAVA_HOME is set to "c:jdk1.7.0_45"
and in the POM I have the following
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_HOME}\jdk1.7.0_45\bin\javac</executable>
<compilerVersion>1.7</compilerVersion>
<configuration>
</plugin>
but have also tried
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
So Why do I get the error: multi-catch statement is not supported in -source 1.5?
I don't see anything that references 1.5.
Also, I am not clear on what the source and target are exactly am only assuming things, same for what maven-compiler-plugin is to stand for.
Any straight forward answers to these questions would be greatly appreciated as I'm new and not aware to go read up on the section I don't know about because what I'm working on I don't know what it's called nor what I am to be asking what I am to be looking up. Nobody in house has a clue either as to how to use Maven. Appreciate any guidance in this painful environment.
===========================
The following is how I had to have it in order for the default of 1.5 not to execute.
Changed the JAVA_HOME to the JDK 1.7 path.
<configuration>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<source>1.7</source>
<target>1.7</target>
</configuration>
However, other projects that require the 1.6 are now broken. What a horrible setup.
For maven compiler plugin, as explained here
the default source setting is 1.5 and the default target setting is
1.5
Also as mentioned in the link you can try the configuration "forceJavacCompilerUse"
try using
<properties>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.test.skip>true</maven.test.skip>
</properties>

findbugs maven plugin site vs check

I'm just trying to wrap my head around a couple of things.
If I have this in my masterpom:
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<failOnError>false</failOnError>
<threshold>High</threshold>
<effort>Default</effort>
<xmlOutput>true</xmlOutput>
<skip>${skipFindBugs}</skip>
<xmlOutputDirectory>target/reports/findbugs</xmlOutputDirectory>
<excludeFilterFile>
src/main/resources/findbugs-exclude-filters.xml
</excludeFilterFile>
</configuration>
</plugin>
</plugins>
</reporting>
My findbugs-exclude-filters.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
<Bug category="I18N" />
</Match>
</FindBugsFilter>
QUESTIONS
Why does clean verify site report 2 warnings, but clean verify findbugs:check return 14 bugs? I don't understand what the difference is.
Why does my site report warn about I18N:DM_DEFAULT_ENCODING
The findbugs-maven-plugin plugin needs to be configured in BOTH the <reporting><plugins/></reporting> and <build><plugins/></build> section. Have experimented with this all sorts of ways and the only way I have been able to get it to work is to duplicate findbugs-maven-plugin configuration.
So try adding something like the following in your pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<failOnError>false</failOnError>
<threshold>High</threshold>
<effort>Default</effort>
<xmlOutput>true</xmlOutput>
<skip>${skipFindBugs}</skip>
<xmlOutputDirectory>target/reports/findbugs</xmlOutputDirectory>
<excludeFilterFile>
src/main/resources/findbugs-exclude-filters.xml
</excludeFilterFile>
</configuration>
</plugin>
</plugins>
</build>
Note that it's a cut and paste of what you posted inside of the <reporting/> block. I have not tested the above. I'm just trying to give you a general idea here.
The Reporting section of the POM Reference states that:
And the subtler difference is that a plugin configuration under the reporting element works as build plugin configuration, although the opposite is not true (a build plugin configuration does not affect a reporting plugin).
I have been able to make this work with Maven 3.0.5. I have not tried it on 3.1.0 yet.

Generating Multiple TLDs With Maven Javadoc Plugin & TLDGen

I've got a taglib project that I use the TLDGen library to help build my TLD files from annotations in my classes. I've then got it plugged into the Maven JavaDoc plugin to have it build the TLD files via the javadoc:javadoc Maven goal. Pom portion that handles this is as follows:
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<configuration>
<doclet>org.tldgen.TldDoclet</doclet>
<docletArtifact>
<groupId>com.google.code.tldgen</groupId>
<artifactId>tldgen-all</artifactId>
<version>1.0.0</version>
</docletArtifact>
<show>private</show>
<additionalparam>-name test
-uri "http://www.mycompany.com/tags/wibble"
-tldFile ..\..\..\src\main\resources\META-INF\w.tld
</additionalparam>
<useStandardDocletOptions>true</useStandardDocletOptions>
<author>false</author>
<encoding>utf-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
And this works fantastically. Trouble is that I know want to create 2 TLD's from this project. I can pass a -subpackages attribute in th addtionalparam element so I can produce a TLD with exactly what I want.
But I can only have one configuration element at that point. I've tried moving the configuration into the reporting section in my pom with two reportsets to see if that helps but no luck.
Has anyone ever attempted this before and can help point me in the right direction for getting it right? Cheers!
It's been a while since this question was posted, but here's how I did multiple tld generation with TLDGen. I started from your question, since the guys over at the project used your answer as a reference :).
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<configuration>
<includes>
<include>**</include>
</includes>
<doclet>org.tldgen.TldDoclet</doclet>
<docletArtifacts>
<!-- listing all dependencies for tldgen:
the tldgen library, commons-logging, commons-io,
commons-lang, geronimo-jsp_2.1_spec, log4j, saxon, stax
not sure if they have to be listed here, will have to check; if I
don't set them I get class not found errors, but I'm guessing I
have a misconfiguration -->
</docletArtifacts>
<show>private</show>
<additionalparam>
-htmlFolder ${basedir}/target/docs
-tldFolder ${basedir}/src/main/java/META-INF
-license NONE
</additionalparam>
<useStandardDocletOptions>true</useStandardDocletOptions>
<author>false</author>
<encoding>utf-8</encoding>
</configuration>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jsr173_api</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>javadoc</goal>
</goals>
</execution>
</executions>
</plugin>

Resources