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>
Related
I have the issue that my mvn compile fails on an internal project for some reason. Two other colleagues tried it as well and it does not fail on their machines.
We use Lombok there (I am not a fan but that was not my choice) and for some reason it fails with a StackOverflowError. After some research I found a solution, adding:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<fork>true</fork>
<compilerArgs>
<arg>-J-Xss4M</arg>
</compilerArgs>
</configuration>
</plugin>
This works fine, but I'd like not to change the pom.xml if this only happens on my machine. So is there a way to add the Xss flag to some environment variable?
I tried to add it via MAVEN_OPTS, in Windows as well as in IntelliJ -> Maven Runner Settings, with and without -Jin front, but it fails as before.
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 did a maven plugin that overwrites "maven-jar-plugin" following this doc:
How do I create a new packaging type for Maven?
you can find my plugin here:
http://mvnrepository.com/artifact/org.lucee/lco-plugin/1.0
the source is here:
https://github.com/lucee/lco-maven-plugin
I only change the extension, nothing else, i get the right extension as expected, problem is the configuration is ignored
<plugin>
<groupId>org.lucee</groupId>
<artifactId>lco-plugin</artifactId>
<version>1.01-SNAPSHOT</version>
<!-- when I use this the configuration works!
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>-->
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
<extensions>true</extensions>
</plugin>
any idea what i do wrong?
You can do further debugging by running your maven build with the -X -e flags activated. This way, you'll see for each running plugin which configuration is loaded.
As the configuration is not loaded, I would suggest it's typically an activation issue that the aforementionned method will allow you to solve.
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.