Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.4
    • Labels:
      None

      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.

      1. trial-maven.zip
        20 kB
        Martin Ackermann
      2. JavacCompiler.java
        29 kB
        Alex Ioffe
      3. JavacCompiler.patch
        0.6 kB
        Alex Ioffe
      4. werror.zip
        5 kB
        Alex Ioffe

        Issue Links

          Activity

          Hide
          Benson Margulies added a comment -

          Here's the story.

          If you are compiling down with -source / -target, and not supplying -Xbootclasspath, you get a warning at the outset. That stops the process with -Werror unless you then also use -Xlint:-options to turn this off. I can't explain the apparent influence of deprecation/warning control.

          Show
          Benson Margulies added a comment - Here's the story. If you are compiling down with -source / -target, and not supplying -Xbootclasspath, you get a warning at the outset. That stops the process with -Werror unless you then also use -Xlint:-options to turn this off. I can't explain the apparent influence of deprecation/warning control.
          Hide
          Benson Margulies added a comment - - edited

          The problem here is

           <showDeprecation>true</showDeprecation>
          

          If this is present, the warnings disappear with -Werror.

          Show
          Benson Margulies added a comment - - edited The problem here is <showDeprecation> true </showDeprecation> If this is present, the warnings disappear with -Werror.
          Hide
          Benson Margulies added a comment - - edited

          I'm reopening this because the 'fix' has a pretty major problem: no message is printed explaining why the compilation fails. Adding -e and -X do not lead to the actual message arriving.

          [INFO] Changes detected - recompiling the module!
          [INFO] Compiling 179 source files to /Users/benson/x/gcoref/core/target/classes
          [INFO] ------------------------------------------------------------------------
          [INFO] BUILD FAILURE
          [INFO] ------------------------------------------------------------------------
          [INFO] Total time: 4.000 s
          [INFO] Finished at: 2015-01-26T13:50:23-05:00
          [INFO] Final Memory: 30M/705M
          [INFO] ------------------------------------------------------------------------
          [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project res-core: Compilation failure -> [Help 1]
          [ERROR]
          [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
          [ERROR] Re-run Maven using the -X switch to enable full debug logging.
          

          Here's the effective pom of note:

                    <execution>
                      <id>default-compile</id>
                      <phase>compile</phase>
                      <goals>
                        <goal>compile</goal>
                      </goals>
                      <configuration>
                        <compilerArgs>
                          <arg>-Werror</arg>
                          <arg>-Xlint:all</arg>
                        </compilerArgs>
                        <showDeprecation>true</showDeprecation>
                        <showWarnings>true</showWarnings>
                        <fork>true</fork>
                        <verbose>true</verbose>
                        <encoding>utf-8</encoding>
                        <source>1.7</source>
                        <target>1.7</target>
                        <maxmem>256M</maxmem>
                        <debug>true</debug>
                        <optimize>true</optimize>
                      </configuration>
                    </execution>
          
          Show
          Benson Margulies added a comment - - edited I'm reopening this because the 'fix' has a pretty major problem: no message is printed explaining why the compilation fails. Adding -e and -X do not lead to the actual message arriving. [INFO] Changes detected - recompiling the module! [INFO] Compiling 179 source files to /Users/benson/x/gcoref/core/target/classes [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 4.000 s [INFO] Finished at: 2015-01-26T13:50:23-05:00 [INFO] Final Memory: 30M/705M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project res-core: Compilation failure -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. Here's the effective pom of note: <execution> <id> default -compile</id> <phase>compile</phase> <goals> <goal>compile</goal> </goals> <configuration> <compilerArgs> <arg>-Werror</arg> <arg>-Xlint:all</arg> </compilerArgs> <showDeprecation> true </showDeprecation> <showWarnings> true </showWarnings> <fork> true </fork> <verbose> true </verbose> <encoding>utf-8</encoding> <source>1.7</source> <target>1.7</target> <maxmem>256M</maxmem> <debug> true </debug> <optimize> true </optimize> </configuration> </execution>
          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!
          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 -

          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.
          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 -

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

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

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

          here's a patch

          Show
          Alex Ioffe added a comment - here's a patch
          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
          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.

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development