Uploaded image for project: 'Maven Compiler Plugin'
  1. Maven Compiler Plugin
  2. MCOMPILER-48

Add maven.compile.failonerror equivalent functionality

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • None
    • 2.0.2
    • None

    Description

      Maven 1.x's "java" plugin offered a maven.compile.failonerror property, which could be set false in order to skip compilation errors.

      I am working on a code generation framework that uses a Maven plugin. The mojo spawns a parallel lifecycle via @execute phase="test-compile", as the mojo itself is @phase generate-sources. This is necessary as the code generator needs to instantiate certain classes to obtain metadata. The nature of the generated types means that users might write code that depends on the generated types to already be compiled on the classpath, although this has not yet happened at this phase because the code generator requires compiled classes first. By the time the generated-sources phase completes and releases to the original lifecycle, the subsequent compilation will work as the generated sources are now available for compilation.

      In practice this issue is easily resolved if AbstractCompilerMojo supported the Maven 1 style maven.compile.failonerror = false property, which could be injected via the MavenProject class during the parallel lifecycle (and reverted upon completion). The relevant lines are:

      504 if ( compilationError )
      505

      { 506 throw new CompilationFailureException( messages ); 507 }

      508 else
      509 {
      510 for ( Iterator i = messages.iterator(); i.hasNext(); )
      511

      { 512 CompilerError message = (CompilerError) i.next(); 513 514 getLog().warn( message.toString() ); 515 }

      516 }

      Could you change line 504 to reference an injected property, so the exception can be consumed with simply a warning?

      At present I am planning on working around this issue by using exclude filters (excluding common filename patterns users are likely to generated dependent code for) but this is an inelegant solution by comparison with supporting the injected property. If there is another way to skip errors and I am not aware of it, would you please let me know. Thanks.

      Attachments

        1. patch.txt
          3 kB
          Ben Alex
        2. compiler-failonerror-test.zip
          2 kB
          Ben Alex
        3. compiler-failonerror-test.zip
          2 kB
          Ben Alex

        Activity

          People

            carlos Carlos Sanchez Gonzalez
            balex Ben Alex
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: