Maven Compiler Plugin
  1. Maven Compiler Plugin
  2. MCOMPILER-120

Javac compiler plugin doesn't support -Werror

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major 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.

        Issue Links

          Activity

          Hide
          Martin Ackermann added a comment -

          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.

          Show
          Martin Ackermann added a comment - 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.
          Hide
          Alex Ioffe added a comment -

          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 )

          { isError = false; msg = msg.substring( warnPrefix.length() ); }

          ... and then it works as expected.

          Show
          Alex Ioffe added a comment - 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 ) { isError = false; msg = msg.substring( warnPrefix.length() ); } ... and then it works as expected.
          Hide
          Alex Ioffe added a comment -

          here's a patch

          Show
          Alex Ioffe added a comment - here's a patch
          Hide
          Anders Hammar added a comment -

          I think there should be an IT as well to get this applied.

          Show
          Anders Hammar added a comment - I think there should be an IT as well to get this applied.
          Hide
          Wendy Smoak added a comment -

          There's already a sample project attached. Are there some docs available on how to turn it into an integration test?

          Show
          Wendy Smoak added a comment - There's already a sample project attached. Are there some docs available on how to turn it into an integration test?
          Hide
          Alex Ioffe added a comment -

          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.

          Show
          Alex Ioffe added a comment - 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.
          Hide
          Kristian Rosenvold added a comment -

          Does this bug actually affect the latest version of the compiler plugin ? I seem to have trouble reproducing it on 2.3.2...?

          Show
          Kristian Rosenvold added a comment - Does this bug actually affect the latest version of the compiler plugin ? I seem to have trouble reproducing it on 2.3.2...?
          Hide
          Alex Ioffe added a comment -

          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.

          Show
          Alex Ioffe added a comment - 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.
          Hide
          Alex Ioffe added a comment -

          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.

          Show
          Alex Ioffe added a comment - 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.
          Hide
          Kristian Rosenvold added a comment -

          Plexus compiler fixed in 633f437fc9fa52aab00da8b7fe7fbf09c93f7219. 1.8.2 will be on central shortly.

          Show
          Kristian Rosenvold added a comment - Plexus compiler fixed in 633f437fc9fa52aab00da8b7fe7fbf09c93f7219. 1.8.2 will be on central shortly.
          Hide
          Kristian Rosenvold added a comment -

          compiler plugin fixed in r1133088

          Integration test based on test project supplied by Martin Ackermann, added to the standard maven-invoker based IT suite.

          Show
          Kristian Rosenvold added a comment - compiler plugin fixed in r1133088 Integration test based on test project supplied by Martin Ackermann, added to the standard maven-invoker based IT suite.
          Hide
          Alex Ioffe added a comment -

          Thanks a lot guys. This will really help.

          Show
          Alex Ioffe added a comment - Thanks a lot guys. This will really help.
          Hide
          Steven Schlansker added a comment -

          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

          Show
          Steven Schlansker added a comment - 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
          Hide
          Robert Scholte added a comment -

          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.

          Show
          Robert Scholte added a comment - 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.
          Hide
          Steven Schlansker added a comment -

          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!)

          Show
          Steven Schlansker added a comment - 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!)
          Show
          Steven Schlansker added a comment - Ref: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-compiler/1.8.2/plexus-compiler-1.8.2.pom
          Hide
          Steven Schlansker added a comment -

          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.

          Show
          Steven Schlansker added a comment - 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.
          Hide
          Kristian Rosenvold added a comment - - edited

          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>
          
          Show
          Kristian Rosenvold added a comment - - edited 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>
          Hide
          Steven Schlansker added a comment - - edited

          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!

          Show
          Steven Schlansker added a comment - - edited 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!

            People

            • Assignee:
              Kristian Rosenvold
              Reporter:
              Christopher Webster
            • Votes:
              2 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: