I just set up a new project using maven 3. I added the following statement to my code:
if(5==5){
}
Which results in a comparing identical expressions warning in eclipse.
I use the following configuration for the maven-compiler-plugin:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerArgument>-Xlint:unchecked</compilerArgument>
<optimize>true</optimize>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
But it refuses to show the warning.
What should I try next?
The Xlint argument you're specifying will cause the javac compiler to warn about unchecked generic operations but, even with the other -Xlint options, there's no way to get the warning you're after from javac.
You'll need to configure your build to use the Eclipse compiler. See the Maven documentation for how to use a non-javac compiler.
Related
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>
According to documentation, I can configure maven-compiler-plugin to show warnings using the <showWarnings> tag :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
I can also configure the plugin to pass arguments to javac, in particular -Xlint:all which "enables all recommended warnings" :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<compilerArgs>
<arg>-Xlint:all</arg>
</compilerArgs>
</configuration>
</plugin>
Are these two options strictly equivalent ? If not, what is the difference ?
The compilerArgs controls the behaviour of the java compiler. These settings are passed on to the compiler, and not used directly by the maven-compiler-plugin. Using Xlint you can control which warnings the java compiler outputs from the compilation process. You can also add e.g. -Werror to abort compilation upon warnings (which in general is a good practice).
The showWarnings configuration on the other hand, is a setting for the maven-compiler-plugin (not passed on to the java compiler). It controls whether the plugin will output the warnings generated by the java compiler. So if you set it to false (I really don't understand why that is the default), you won't see the warnings generated by the java compiler. Even worse, the build will not fail even if you have set -Werror in the compilerArgs.
We setup the compiler plugin in a dedicated parent pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
But the javadoc plugin (version 2.9.1) fails with error:
error: lambda expressions are not supported in -source 1.7
If i run with "-X" i only see that indeed source is set to 1.7: source = 1.7
So the question is why?
(the normal build works fine!)
I also tried to explicitly set source either by property maven.compiler.source or by plugin configuration - i put the compiler plugin configuration from above into the project.
So how to get it working?
I use maven-compiler-plugin to compile the project. With current configuration when project is building I get the WARNING in the log. My requirement is that how can I suppress the warnings when project build. Please let me know.
POM configuration
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<failOnError>false</failOnError>
</configuration>
</plugin>
See javac - Java programming language compiler, Options:
An additional set of non-standard options are specific to the current virtual machine and compiler implementations and are subject to change in the future. Non-standard options begin with -X.
...
-Xlint:none Disable all warnings.
See also How to get compiler warnings when building a Jenkins plugin:
<configuration>
<compilerArgument>-Xlint:none</compilerArgument>
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>