Class AbstractCompilerMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
    Direct Known Subclasses:
    CompilerMojo, TestCompilerMojo

    public abstract class AbstractCompilerMojo
    extends org.apache.maven.plugin.AbstractMojo
    TODO: At least one step could be optimized, currently the plugin will do two scans of all the source code if the compiler has to have the entire set of sources. This is currently the case for at least the C# compiler and most likely all the other .NET compilers too.
    Since:
    2.0
    Author:
    others, Trygve Laugstøl
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.List<java.lang.String> compilerArgs
      Sets the arguments to be passed to the compiler.
      protected java.lang.String compilerArgument
      Sets the unformatted single argument string to be passed to the compiler.
      protected java.util.Map<java.lang.String,​java.lang.String> compilerArguments
      Deprecated.
      use compilerArgs instead.
      protected static java.lang.String PS  
      protected java.lang.String release
      The -release argument for the Java compiler, supported since Java9
      protected java.lang.String source
      The -source argument for the Java compiler.
      protected java.lang.String target
      The -target argument for the Java compiler.
      • Fields inherited from interface org.apache.maven.plugin.Mojo

        ROLE
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void execute()  
      protected java.util.Date getBuildStartTime()  
      protected abstract java.util.List<java.lang.String> getClasspathElements()  
      protected abstract java.lang.String getCompilerArgument()  
      protected abstract java.util.Map<java.lang.String,​java.lang.String> getCompilerArguments()  
      protected abstract java.util.List<java.lang.String> getCompileSourceRoots()  
      protected abstract java.lang.String getDebugFileName()  
      protected abstract java.util.Set<java.lang.String> getExcludes()  
      protected abstract java.io.File getGeneratedSourcesDirectory()  
      protected abstract java.util.Set<java.lang.String> getIncludes()  
      protected static int getJavaMajorVersion​(java.lang.String version)
      Returns the major Java version from its legacy or current string representation.
      protected java.util.Optional<java.nio.file.Path> getModuleDeclaration​(java.util.Set<java.io.File> sourceFiles)  
      protected abstract java.util.List<java.lang.String> getModulepathElements()  
      protected abstract java.io.File getOutputDirectory()  
      protected abstract java.util.Map<java.lang.String,​org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor> getPathElements()  
      protected org.apache.maven.project.MavenProject getProject()  
      protected static java.util.List<java.io.File> getProjectOutputDirectories​(java.io.File outputDirectory, int release)
      Returns existing multirelease JAR output directories through the given release in descending order.
      protected abstract java.lang.String getRelease()  
      protected int getRequestThreadCount()
      try to get thread count if a Maven 3 build, using reflection as the plugin must not be maven3 api dependent
      protected abstract java.lang.String getSource()  
      protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner getSourceInclusionScanner​(int staleMillis)  
      protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner getSourceInclusionScanner​(java.lang.String inputFileEnding)  
      protected abstract java.lang.String getTarget()  
      protected org.apache.maven.toolchain.Toolchain getToolchain()  
      protected boolean isTestCompile()  
      protected abstract void preparePaths​(java.util.Set<java.io.File> sourceFiles)  
      void setRelease​(java.lang.String release)  
      void setTarget​(java.lang.String target)  
      • Methods inherited from class org.apache.maven.plugin.AbstractMojo

        getLog, getPluginContext, setLog, setPluginContext
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PS

        protected static final java.lang.String PS
      • source

        @Parameter(property="maven.compiler.source",
                   defaultValue="1.8")
        protected java.lang.String source

        The -source argument for the Java compiler.

        NOTE:

        Since 3.8.0 the default value has changed from 1.5 to 1.6

        Since 3.9.0 the default value has changed from 1.6 to 1.7

        Since 3.11.0 the default value has changed from 1.7 to 1.8

        See Also:
        javac -source
      • target

        @Parameter(property="maven.compiler.target",
                   defaultValue="1.8")
        protected java.lang.String target

        The -target argument for the Java compiler.

        NOTE:

        Since 3.8.0 the default value has changed from 1.5 to 1.6

        Since 3.9.0 the default value has changed from 1.6 to 1.7

        Since 3.11.0 the default value has changed from 1.7 to 1.8

        See Also:
        javac -target
      • release

        @Parameter(property="maven.compiler.release")
        protected java.lang.String release
        The -release argument for the Java compiler, supported since Java9
        Since:
        3.6
        See Also:
        javac -release
      • compilerArguments

        @Parameter
        @Deprecated
        protected java.util.Map<java.lang.String,​java.lang.String> compilerArguments
        Deprecated.
        use compilerArgs instead.

        Sets the arguments to be passed to the compiler (prepending a dash).

        This is because the list of valid arguments passed to a Java compiler varies based on the compiler version.

        Note that -J options are only passed through if fork is set to true.

        To pass -Xmaxerrs 1000 -Xlint -Xlint:-path -Averbose=true you should include the following:

         <compilerArguments>
           <Xmaxerrs>1000</Xmaxerrs>
           <Xlint/>
           <Xlint:-path/>
           <Averbose>true</Averbose>
         </compilerArguments>
         
        Since:
        2.0.1
      • compilerArgs

        @Parameter
        protected java.util.List<java.lang.String> compilerArgs

        Sets the arguments to be passed to the compiler.

        Note that -J options are only passed through if fork is set to true.

        Example:
         <compilerArgs>
           <arg>-Xmaxerrs</arg>
           <arg>1000</arg>
           <arg>-Xlint</arg>
           <arg>-J-Duser.language=en_us</arg>
         </compilerArgs>
         
        Since:
        3.1
        See Also:
        javac -J
      • compilerArgument

        @Parameter
        protected java.lang.String compilerArgument

        Sets the unformatted single argument string to be passed to the compiler. To pass multiple arguments such as -Xmaxerrs 1000 (which are actually two arguments) you have to use compilerArgs.

        This is because the list of valid arguments passed to a Java compiler varies based on the compiler version.

        Note that -J options are only passed through if fork is set to true.

        See Also:
        javac -J
    • Constructor Detail

      • AbstractCompilerMojo

        public AbstractCompilerMojo()
    • Method Detail

      • getSourceInclusionScanner

        protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner getSourceInclusionScanner​(int staleMillis)
      • getSourceInclusionScanner

        protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner getSourceInclusionScanner​(java.lang.String inputFileEnding)
      • getClasspathElements

        protected abstract java.util.List<java.lang.String> getClasspathElements()
      • getModulepathElements

        protected abstract java.util.List<java.lang.String> getModulepathElements()
      • getPathElements

        protected abstract java.util.Map<java.lang.String,​org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor> getPathElements()
      • getCompileSourceRoots

        protected abstract java.util.List<java.lang.String> getCompileSourceRoots()
      • preparePaths

        protected abstract void preparePaths​(java.util.Set<java.io.File> sourceFiles)
      • getOutputDirectory

        protected abstract java.io.File getOutputDirectory()
      • getSource

        protected abstract java.lang.String getSource()
      • getTarget

        protected abstract java.lang.String getTarget()
      • getRelease

        protected abstract java.lang.String getRelease()
      • getCompilerArgument

        protected abstract java.lang.String getCompilerArgument()
      • getCompilerArguments

        protected abstract java.util.Map<java.lang.String,​java.lang.String> getCompilerArguments()
      • getGeneratedSourcesDirectory

        protected abstract java.io.File getGeneratedSourcesDirectory()
      • getDebugFileName

        protected abstract java.lang.String getDebugFileName()
      • getProject

        protected final org.apache.maven.project.MavenProject getProject()
      • getModuleDeclaration

        protected final java.util.Optional<java.nio.file.Path> getModuleDeclaration​(java.util.Set<java.io.File> sourceFiles)
      • getProjectOutputDirectories

        protected static java.util.List<java.io.File> getProjectOutputDirectories​(java.io.File outputDirectory,
                                                                                  int release)
        Returns existing multirelease JAR output directories through the given release in descending order. The base output directory is returned last.
      • getJavaMajorVersion

        protected static int getJavaMajorVersion​(java.lang.String version)
        Returns the major Java version from its legacy or current string representation.
      • isTestCompile

        protected boolean isTestCompile()
      • getIncludes

        protected abstract java.util.Set<java.lang.String> getIncludes()
      • getExcludes

        protected abstract java.util.Set<java.lang.String> getExcludes()
      • getRequestThreadCount

        protected int getRequestThreadCount()
        try to get thread count if a Maven 3 build, using reflection as the plugin must not be maven3 api dependent
        Returns:
        number of thread for this build or 1 if not multi-thread build
      • getBuildStartTime

        protected java.util.Date getBuildStartTime()
      • getToolchain

        protected final org.apache.maven.toolchain.Toolchain getToolchain()
      • setTarget

        public void setTarget​(java.lang.String target)
      • setRelease

        public void setRelease​(java.lang.String release)