Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.1
-
Fix Version/s: 2.4
-
Labels:None
-
Number of attachments :4
Description
If I write a pom file like the following:
... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.1</version> <configuration> <compilerId>javac</compilerId> <source>1.6</source> <target>1.6</target> <compilerArguments> <Werror /> <Xlint:all /> </compilerArguments> <showDeprecation>true</showDeprecation> </configuration> </plugin>
and if there are only warnings, then the build will not fail as intended by the compiler Argument. The reason is that in compileInProcess the exit code from javac is only considered if there are no messages. In the case of treating warnings as errors, there will be messages but no errors so the intention of the build failure is lost.
-
Hide
- trial-maven.zip
- 13/Feb/11 7:05 AM
- 20 kB
- Martin Ackermann
-
- trial-maven/.project 0.4 kB
- trial-maven/.../org.maven.ide.eclipse.prefs 0.2 kB
- trial-maven/pom.xml 5 kB
- trial-maven/.../trial-maven site-deploy.launch 1 kB
- trial-maven/src/site/site.xml 2 kB
- trial-maven/.../.classpath 0.7 kB
- trial-maven/.../.project 0.6 kB
- trial-maven/.../org.eclipse.jdt.core.prefs 0.3 kB
- trial-maven/.../org.maven.ide.eclipse.prefs 0.2 kB
- trial-maven/.../pom.xml 0.5 kB
- trial-maven/.../pmd-ruleset.xml 15 kB
- trial-maven/trial-maven-product/.project 0.4 kB
- trial-maven/.../org.maven.ide.eclipse.prefs 0.3 kB
- trial-maven/trial-maven-product/pom.xml 2 kB
- trial-maven/.../.classpath 0.7 kB
- trial-maven/trial-maven-product/.../.project 0.6 kB
- trial-maven/.../org.eclipse.jdt.core.prefs 0.3 kB
- trial-maven/.../org.maven.ide.eclipse.prefs 0.2 kB
- trial-maven/trial-maven-product/.../pom.xml 1.0 kB
- trial-maven/.../MyClass.java 0.1 kB
- trial-maven/trial-maven-product/.../site.xml 0.6 kB
- trial-maven/.../MyClassTest.java 0.6 kB
-
- JavacCompiler.java
- 16/May/11 6:46 PM
- 29 kB
- Alex Ioffe
-
- JavacCompiler.patch
- 16/May/11 6:54 PM
- 0.6 kB
- Alex Ioffe
-
Hide
- werror.zip
- 06/Jun/11 12:37 PM
- 5 kB
- Alex Ioffe
-
- werror/pom.xml 2 kB
- werror/warningsbuild/pom.xml 2 kB
- werror/src/test/.../test/WerrorTest.java 2 kB
- werror/warningsbuild/src/.../test/Main.java 0.2 kB
Issue Links
- relates to
-
MCOMPILER-179
Warnings
-
Activity
I think the fix is trivial, in 'parseModernError' switch the order of:
isError = exitCode != 0;
and:
// Remove the 'warning: ' prefix
String warnPrefix = getWarnPrefix( msg );
if ( warnPrefix != null )
... and then it works as expected.
There's already a sample project attached. Are there some docs available on how to turn it into an integration test?
Okay guys... here's your integration test. Its a simple JUnit module called 'WerrorTest.java' which uses MavenCli to call the 'compile' command on the inner module and checks that the maven output (of this invocation) contains a "unchecked call to add(e)" and has a return code 1. If these conditions are met, the unit test passes.
Does this bug actually affect the latest version of the compiler plugin ? I seem to have trouble reproducing it on 2.3.2...?
This does not directly stem from maven-compiler-plugin, it has to do with the plexus-compiler-javac and it does effect the latest version of it (1.8.1 etc...). If you take a look at werror.zip/warningsbuild/pom.xml you will see a explicit dependency plexus-compiler-javac under maven-compiler-plugin.
Just a little clarification, in the inner pom (werror.zip/warningsbuild/pom.xml) file you will see an entry for plexus-compiler-javac version '1.8.2-SNAPSHOT'. In order to run the integration test, go to the outer pom file (werror.zip/pom.xml) and run 'mvn test' which will run the integration test.
This integration test does nothing more then call 'mvn compile' on the inner pom file and then checks the output/return code of it. In order to successfully pass the test, the inner pom file should fail the build and have a return code 1.
In order to have this integration test pass, you have to get the code for plexus-compiler-javac (svn info here: http://plexus.codehaus.org/plexus-utils/source-repository.html), make the code change to the JavacCompiler, and then deploy it to a local repo. The inner pom file will pick it up, the inner build will fail, and the integration test will pass.
Plexus compiler fixed in 633f437fc9fa52aab00da8b7fe7fbf09c93f7219. 1.8.2 will be on central shortly.
compiler plugin fixed in r1133088
Integration test based on test project supplied by Martin Ackermann, added to the standard maven-invoker based IT suite.
It seems that maven-compiler-plugin 2.4 still hasn't been released... I don't suppose that it's easy to do that? I'd love to use this bug fix but I don't want to maintain my own build unless I have to ![]()
It's not that hard, but we've provided some other patches for the plexus-compiler-javac. Would be nice if that one is released first before releasing the next m-compiler-p.
Kristian commented above that the Plexus compiler was fixed and that 1.8.2 was released... I can confirm that I see 1.8.2 on various Maven mirrors. Is that not sufficient? (Sorry, I don't know too much about the dependencies here, I just want to offer to go bug whoever is blocking this from getting out so I can use it!)
I've sent a mail to the plexus compiler user list in the hopes that there are in fact additional issues fixed worthy of a new release.
You can add plexus-compiler manually to maven-compiler-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId>
<version>1.8.2</version>
</dependency>
</dependencies>
</plugin>
Thank you, I had to do this actually:
<!-- Remove after we move to maven-compiler-plugin 2.4 -->
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-api</artifactId>
<version>1.8.2</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-manager</artifactId>
<version>1.8.2</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac</artifactId>
<version>1.8.2</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
but it does work now!
Attached example project. Just run "mvn compile". trial-maven-product-child logs a compiler warning, but maven finishes with "Success".
Environment: Windows XP SP3, Maven 3.0.1, Maven Compiler Plugin 2.3.2, javac from jdk1.6.0_11.
The bug is critical for production builds: Builds with compiler warnings should not be used in production.